Changing webkit transition duration with javascript - php

I have a ticker-tape run of text but I would like to change the duration of the duration depending on the amount of text to be shown. When the amount is small, the text runs slowly which is fine but with a lot of text, the tape whizzes by.
.marquee {
/* margin-left: auto;
margin-right: auto; */
width: 800px;
height: 25px;
margin: 0 auto;
white-space: nowrap;
overflow: hidden;
border: 1px solid #FF0000;
background: GhostWhite;
color: black;
font-size: 20px;
}
.marquee span {
display: inline-block;
padding-left: 100%;
animation: marquee 20s linear infinite;
}
/* Make it move */
#keyframes marquee {
0% { transform: translate(0, 0); }
100% { transform: translate(-100%, 0); }
}
In the html, I am running the span as follows:
<p class="marquee"><span><?php echo getEvents(); ?></span></p>
getEvents() is a php function that populates the ticker; from this I'd like to determine the length of text to throttle the speed of the text

It is the 20s in animation directive that says how much time the text has to move across its container. Short text will move slowly to cover the distance in 20 seconds. Much longer text will have to move much faster.
See this JSfiddle: https://jsfiddle.net/s40e3Lng/2/
The following JS/jquery sets the time to cross the <p> to a formula based on length of of the string inside the .
$('p.marquee span').each(function() {
var len = $(this).html().length;
var speed = 100;
var time = 4 + (4*len)/speed;
$(this).attr('style', 'animation: marquee '+time+'s linear infinite;');
});
In the JSfiddle, you can play around with the formula until you get a speed you like. Just change the JS code and click "Run" in top-left.

if you change your html so that
<p class="marquee" id="mID">
you could then use javascript to manipulate the elements of your
document.getElementById("mID").style.WebkitTransitionDuration = "1s"; // Code for Safari 3.1 to 6.0
document.getElementById("mID").style.transitionDuration = "1s";

Related

Wordpress post display in different pages separate by section H1

i want to display the following Post in 3 different sections. The first section is the table of content. The second is the summary and the third is the theory. Is like a multipage post but each page has a section, as I don't want to show all the information in a single page.
Thanks in advance
The way I have come up with this is this way.
I'm only posting these because I have it all setup so I can basically copy and paste it in. Next time I want to see more effort on your part.
Create a new JS file. well call it mytabs.js in that file put this:
;( function( $, window, document, undefined ) {
"use strict";
$( document ).ready( function() {
var loadTabOrder = function(id){
// Define friendly data store name
var dataStore = window.sessionStorage;
var oldIndex = 0;
// Start magic!
try {
// getter: Fetch previous value
oldIndex = dataStore.getItem(id);
} catch(e) {}
return oldIndex;
};
var saveTabOrder = function(id, currentIndex){
// Define friendly data store name
var dataStore = window.sessionStorage;
// Start magic!
try {
dataStore.setItem( id, currentIndex );
} catch(e) {}
};
$('.ui-tabs-vertical').each(function(){
var id = $(this).prop('id');
if(!id) $.error('.ui-tabs-vertical requires an id');
var element = $( "#"+id );
var options = {
active: loadTabOrder(id),
activate: function(event, ui) {
saveTabOrder(id, ui.newTab.parent().children().index(ui.newTab));
}
};
element.tabs(options).addClass( "ui-helper-clearfix" );
var nav = element.find('> .ui-tabs-nav > li');
nav.removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );
var height = 0;
nav.each(function(){
height += $(this).outerHeight();
});
element.find('> .ui-tabs-panel').css(
'min-height',
height+'px'
);
});
} );
} ) ( jQuery, window, document );
Somewhere in your theme/pllugin put this:
//ui css
wp_enqueue_style('jquery-ui');
//jquery
wp_enqueue_script('jquery');
//jquery-ui
wp_enqueue_script('jquery-ui');
//you only need to do the above it you dont have them included already
//add our JS page.
wp_enqueue_script('mytabs', plugin_dir_url(__FILE__).'mytabs.php', ['juery-ui']);
//in my case this is in a plugin file, obviously use your path to your JS file
In your CSS file add these, make sure your CSS loads after jQuery UI
.ui-tabs.ui-tabs-vertical {
padding: 0;
height: 100%;
width: calc(100% - 15px);
position: relative;
}
.ui-tabs.ui-tabs-vertical .ui-widget-header {
border: none;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav {
float: left;
width: 10em;
background: #EEE;
border-radius: 4px 0 0 4px;
border-right: 1px solid gray;
position: absolute;
top : 0;
bottom: 0;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li {
clear: left;
width: 100%;
margin: 0.2em 0;
border: 1px solid gray;
border-width: 1px 0 1px 1px;
border-radius: 4px 0 0 4px;
overflow: hidden;
position: relative;
right: -2px;
z-index: 2;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li a {
display: block;
width: 100%;
padding: 0.6em 1em;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li a:hover {
cursor: pointer;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li.ui-tabs-active {
margin-bottom: 0.2em;
padding-bottom: 0;
border-right: 1px solid white;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li:last-child {
margin-bottom: 10px;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-panel {
float: left;
margin-left: 150px;
width: calc(100% - 200px);
min-width: 600px;
border-radius: 0;
position: relative;
left: -1px;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-panel .panel-title{
padding: 0px;
margin: 0px;
margin-bottom: 10px;
font-size: 22px;
}
In your HTML add something like this
<div id="myttabs" class="ui-tabs-vertical">
<ul>
<li>General</li>
<li>Foo</li>
</ul>
<div id="settings-panel">
<p>Here is some settings</p>
</div>
<div id="foo-panel">
<p>Here is some foo</p>
</div>
</div>
Overview
How it works. In the above HTML you will notice ui-tabs-vertical class. Then in our mytabs.js we do this:
$('.ui-tabs-vertical').each(function(){ ... }
In short what this does is any element that has the ui-tabs-vertical class will get the ui-tabs added automagially. This is especially nice for wordpress as we can get into a real mess trying to put JS in a post (for example). So we want it as clean an free as possible. This trick with some variation can be used on any of the UI elements that create similar stuff, same type of popup, or anything we can normalize to a common format, so we don't have too many arguments.
Pass options -via- data attributes
One way to pass options to the JS, that I didn't need here is to simply put them in a data- attribute on the main element or any element that makes sense. For example you can set .tabs({hide:true}) to hide the tabs.
So if I wanted to do that I would do something like this:
//in our HTML add the data attribute to the main element
<div id="myttabs" class="ui-tabs-vertical" data-hide="true" >
//in myscript.js - change the options object.
var element = $( "#"+id )
var options = {
hide: element.data('hide') | false,
active: loadTabOrder(id),
activate: function(event, ui) {
window.saveTabOrder(id, ui.newTab.parent().children().index(ui.newTab));
}
};
The active tag will be remembered by the users browser by making use of some simple Session Storage stuff in there. These are keyed off the ID of the main HTML element for the tabs. This makes that ID required, so there is a bit of code to issue an error to the console, for development purposes. Its important to use the tabs ID, because that way each tab will have it's own settings remembered. If we mixed them we would probably get some errors for missing tab indexes etc..
There are also some modifications to the vertical CSS to expand the area behind the Tabs. I probably spent the most time on this piece and its a relatively minor visual issue. But I cant have that in my work. This is actually quite tricky to do, as you will see below. It looks way better with the full width background.
You can see this issue even on the jQuery example page.
The way I fixed it was
position:absolute on the navigation box with a top:0 and bottom:0, the parent element should be position:relative. This alone basally solves the 100% height issue, now we have to deal with the side effects of absolute positioning.
A few tricks like this width: calc(100% - 200px); to dynamically get the width set up. Absolute elements are not part of the Box Model of the DOM, so it's very hard to account for them with just CSS as they don't hold any space in the container.
Now all we need to do is set the min-height. The only reason we need to do this is everything goes janky if you have a lot of menu item (absolute) but no content in the tab (height is smaller then the nav). Which will bust it out of the bottom of the ui-tabs container because its absolute positioned. This is because with the top:0 and bottom:0 we are tying the width of the navigation menu to the main ui-tabs container. When the panel is empty that container will be shorter then the menu, which is a problem with many menu items and tiny panels. It can also cause some issues if you load content -via- AJAX, as you may see this error for second while the request goes.
4 So with the last bit of JS we just need to set min-height to apx the same height as the navigation's height. Because the navigation is absolute and tied to the parent container (as I said above, its height is dependent on .ui-tabs), so we can't simply get the height of that. The only option I saw was to sum the height of it's contents, the li elements themselves. This is a bit harder but we only need to do it one time for each ui-tabs.
The absolute position stuff will dynamically adjust the height (with just CSS) if the tab height changes, such as loading content via AJAX or other dynamic stuff.
The .ui-tabs-panel are set to float:left with a margin apx the width of the tab navigation. This accounts for the horizontal space the navigation takes up. Then to get something resembling a proper 100% width, we can use width: calc(100% - 200px); again because the nav is absolute we are sort of stuck manually offsetting for it. So This has 150px for the menus width offset, (or the left-margin on the panel, about the same width as the nav) and an extra 50 for things like the margin on the right and some other padding etc. We could have used negative margins for some of these (but I didn't think about that tell now)
Now having the panel width dynamic and like a real 100% width, all we need to do to make the panel smaller is adjust the width of the container around the main UI-Tabs element. This way we can adjust it without sending any arguments to .tabs() or changing any thing with JS.
As I said that menu thing is a hard problem to solve, this is mainly due to the fact were limited in what we can do structure wise, or we will just break the ui-tabs. So we cant really change that, and that leave only JS and CSS. CSS is preferable because then we don't have to write yet more JS, and we would need to keep watch on the contents changing to resize it. Even then there would be some lag in the change. For example using an setInterval to keep an eye on it, this is something we want to avoid as it can affect performance too, and is more of a headache then the minor visual problem that this is.
Summery
I basically just pasted this from my own plugin, so I can't grantee that I covered everything. I cant stand little quirky things like the images above so I always fix that stuff. And I try to make my life easier later so now we just make the HTML and add the ui-tabs-vertical and mytabs.js takes care of the rest. Lastly we should never have to mess with mytabs.js and anytime we want a tab setup we just add the HTML with that class.
There is probably a tiny performance penalty to this (maybe) but in Wordpress it can be really hard to call JS from posts or other content in a "clean" way. So this just encapsulates all that code and make it a lot cleaner and easier to maintain IMO because, you are not mixing HTML and JS and CSS etc.
Hope it helps:
PS if the way I start my JS looks funny please see this question:
What advantages does using (function(window, document, undefined) { ... })(window, document) confer?
And this one:
How does this JavaScript/JQuery Syntax work: (function( window, undefined ) { })(window)?
Basically its a self executing function that keeps our global JS space clean, so we don't get any conflicts from other plugins, or scripts that may use the same variable names as we are.
I do a fair amount of plugin development, so its a bit more common to use it for that, but I just basically copy and paste it now, so... Also I feel I should mention this is part of a much larger script that dynamically adds a bunch of UI stuff for me. That way when I'm working on HTML, I can just work on HTML etc...
For the final result check this out:
;( function( $, window, document, undefined ) {
"use strict";
$( document ).ready( function() {
var loadTabOrder = function(id){
/*// Define friendly data store name
var dataStore = window.sessionStorage;
var oldIndex = 0;
// Start magic!
try {
// getter: Fetch previous value
oldIndex = dataStore.getItem(id);
} catch(e) {}
return oldIndex;*/
};
var saveTabOrder = function(id, currentIndex){
/*// Define friendly data store name
var dataStore = window.sessionStorage;
// Start magic!
try {
dataStore.setItem( id, currentIndex );
} catch(e) {}*/
};
$('.ui-tabs-vertical').each(function(){
var id = $(this).prop('id');
if(!id) $.error('.ui-tabs-vertical requires an id');
var element = $( "#"+id );
var options = {
active: loadTabOrder(id),
activate: function(event, ui) {
saveTabOrder(id, ui.newTab.parent().children().index(ui.newTab));
}
};
element.tabs(options).addClass( "ui-helper-clearfix" );
var nav = element.find('> .ui-tabs-nav > li');
nav.removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );
var height = 0;
nav.each(function(){
height += $(this).outerHeight();
});
element.find('> .ui-tabs-panel').css(
'min-height',
height+'px'
);
});
$('#expand').click(function(){
$('#'+$( "#mytabs li.ui-tabs-active" ).attr('aria-controls')+' p').css({"height":'300px'});
});
$('#shrink').click(function(){
$('#'+$( "#mytabs li.ui-tabs-active" ).attr('aria-controls')+' p').css({"height":''});
});
} );
} ) ( jQuery, window, document );
.ui-tabs.ui-tabs-vertical {
padding: 0;
height: 100%;
width: calc(100% - 15px);
position: relative;
}
.ui-tabs.ui-tabs-vertical .ui-widget-header {
border: none;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav {
float: left;
width: 10em;
background: #EEE;
border-radius: 4px 0 0 4px;
border-right: 1px solid gray;
position: absolute;
top : 0;
bottom: 0;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li {
clear: left;
width: 100%;
margin: 0.2em 0;
border: 1px solid gray;
border-width: 1px 0 1px 1px;
border-radius: 4px 0 0 4px;
overflow: hidden;
position: relative;
right: -2px;
z-index: 2;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li a {
display: block;
width: 100%;
padding: 0.6em 1em;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li a:hover {
cursor: pointer;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li.ui-tabs-active {
margin-bottom: 0.2em;
padding-bottom: 0;
border-right: 1px solid white;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-nav li:last-child {
margin-bottom: 10px;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-panel {
float: left;
margin-left: 150px;
width: calc(100% - 200px);
min-width: 600px;
border-radius: 0;
position: relative;
left: -1px;
}
.ui-tabs.ui-tabs-vertical .ui-tabs-panel .panel-title{
padding: 0px;
margin: 0px;
margin-bottom: 10px;
font-size: 22px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<div id="mytabs" class="ui-tabs-vertical">
<ul>
<li>General</li>
<li>Foo</li>
</ul>
<div id="settings-panel">
<p>Here is some settings</p>
</div>
<div id="foo-panel">
<p>Here is some foo</p>
</div>
</div>
<div style="margin-top: 20px">
<button id="expand" >Click here to expand the panel</button>
<button id="shrink" >Click here to shrink the panel</button>
</div>
The only notes here, is I added the buttons to showcase how the gray nav background resizes automatically and Stack Overflow wont let me use the sessionStorge here. So I had no choice but to comment it out.
Sense there is so much code, most of it is pretty simple stuff really, I didn't want it all in the snip-it windows, as its a bit harder to read there. So forgive the lengthy post, but I wanted it to all make sense.
Enjoy!

Div positioning on the screen

I have these two styles that position my div in the footer of my page. What happens is that when you generate the content of the page for php, these div can override the content.
div.panel-foot {
position: absolute;
z-index: 2;
height: 30px;
width: 100%;
bottom: 0;
color: white;
background-color: #333333;
white-space: nowrap;
padding: 5px 100px;
}
div.panel-foot-information {
background-color: rgb(65, 65, 65);
position: absolute;
bottom: 30px;
max-width: none !important;
z-index: 1;
color: white;
font-size: small;
padding-top: 10px;
padding-bottom: 10px;
}
So what I do is when the content is small they stay on radapé ie with position: absolute, and when the content is longer they stay position: relative.
Anyone know a solution to resize content dynamically?
Unlike the other answers so far, I'm going to assume you have images and other things that a real website has, besides text.
I suggest using Javascript (since you've got a jQuery tag). PHP ultimately has no idea how much space the content will take up in the browser, so JS is your best option.
Have a look at my example here. If you remove some of the div content, you will see the footer color changes (because it changes the classname). all you have to do is plug in your own selectors and classnames and you're good to go.
// check the size of your conent div
// assuming it's got an id of "content"
contentHeight = $("#content").height();
// set the threshold that will determine how big is too big
threshold = 300;
// or if you want to make the threshold as big as the window...
// threshold = $(window).height();
// if the content height is greater than the threshold..
if(contentHeight > threshold){
// remove one class and add another
$("#footer").removeClass('green');
$("#footer").addClass('red');
}
// otherwise, do the opposite
else{
$("#footer").removeClass('red');
$("#footer").addClass('green');
}

How to prevent PHP pushed HTML tables exceeding the length of the page

I am still a novice and would appreciate any assistance you can provide.
I am trying to prevent an HTML table from exceeding the length of the page. I am currently parsing a csv with PHP and looping the array information into an HTML table.
The table is to be shown on a static 1080p screen so the table itself needs to resize by shrinking cells instead of going off the page horizontally or vertically. I dont mind how squashed the cells become as they are colour coded with CSS.
I have too many lines of code to post here so I will just post my CSS style code which I have attempted to use to contain my table.
<style>
html,body {
background-color: #F4F4F4
margin: 0;
padding: 0;
height: 100%;
border: 0;
}
table{
height:100%;
width:100%;
overflow: hidden;
white-space: nowrap;
}
td {
border: 1px solid black;
resize: both;
overflow: hidden;
}
th {
resize: both;
overflow: auto;
}
</style>
I have tried different variations of the above to no avail e.g. overflow settings, resize settings etc this is just my current test.
I do not care whether I have to use HTML, CSS, Javascript, JQuery or PHP for this. I would rather not have to completely start over however.
Try to include this for your tags:
td.wordbreak {
word-break: break-all;
width: NNNpx;
}
This should sort the problem of cells spiting out your table horizontally.
Replace the NNN by a number in pixels, that could be a fraction of the total you need.
So let's say you had only 2 columns, it would be:
table {
table-layout: fixed; width: 100%;
}
td
{
word-break: break-all;
width: 540px;
}
try to use
table {
table-layout: fixed;
width: 100%;
}
For more check Fixed Table Layouts.
Hope this will help.

css how to increase the size of rounded image button with varying text

Can somebody please help me out on how to increase the size of the rounded button with respect to text. Please check the image:
I want to be able to write any length of text and rounded button will stretch automatically based on text.
Please help me on how to write CSS for to get this working ?
Note: I don't want to use CSS3 border-radius because it does not work in IE and I don't want to use css3pie, etc, that's why i have created the rounded images. Thanks
Use the Sliding Door Principle. http://www.alistapart.com/articles/slidingdoors/.
In sliding doors you have two extreme as images(rounded) between these images is a background. The images move (slide further) based on the length of the text.
ul {
list-style-type: none;
}
ul li {
height: 31px; // height of the background image *reused below
margin: 10px; // width of the left image *reused below
float: left;
background: url(left.png) no-repeat top left;
}
ul li div {
height: 31px;
margin-left: 10px;
padding-right: 10px;
background: url(right.png) no-repeat top right;
}
//used with
<ul>
<li><div>text</div></li>
<li><div>texttexttext</div></li>
<li><div>texttexttexttext</div></li>
</ul>
I would probably opt for creating a div which inherits a css class like the following
<div class="button">TEXT HERE</div>
The CSS would be the following:
.button { border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; background-color: blue; }
The above style would allow all browsers (except older IE's) to render the rounded corners rounded which means you will have no need for images

HTML PHP Progress Bar

I have a website with a form that uses PHP to send the form data. Is there a way to create a progress bar on the page that looks like it is in action, so that people don't click the button more than once after it's clicked and sending the PHP information.
Thanks.
Progress Bar: Simple Text Version :
<?php
// Output a 'waiting message'
echo 'Please wait while this task completes';
// Now while waiting for a certain task to
// complete, keep outputting .'s
while (true) {
// Echo an extra dot, and flush the buffers
// to ensure it gets displayed.
echo ' .';
flush();
// Now sleep for 1 second and check again:
sleep(1);
}
?>
Progress Bar: PHP-Based (grphical) :
<?php
// A function that will create the initial setup
// for the progress bar: You can modify this to
// your liking for visual purposes:
function create_progress() {
// First create our basic CSS that will control
// the look of this bar:
echo "
<style>
#text {
position: absolute;
top: 100px;
left: 50%;
margin: 0px 0px 0px -150px;
font-size: 18px;
text-align: center;
width: 300px;
}
#barbox_a {
position: absolute;
top: 130px;
left: 50%;
margin: 0px 0px 0px -160px;
width: 304px;
height: 24px;
background-color: black;
}
.per {
position: absolute;
top: 130px;
font-size: 18px;
left: 50%;
margin: 1px 0px 0px 150px;
background-color: #FFFFFF;
}
.bar {
position: absolute;
top: 132px;
left: 50%;
margin: 0px 0px 0px -158px;
width: 0px;
height: 20px;
background-color: #0099FF;
}
.blank {
background-color: white;
width: 300px;
}
</style>
";
// Now output the basic, initial, XHTML that
// will be overwritten later:
echo "
<div id='text'>Script Progress</div>
<div id='barbox_a'></div>
<div class='bar blank'></div>
<div class='per'>0%</div>
";
// Ensure that this gets to the screen
// immediately:
flush();
}
// A function that you can pass a percentage as
// a whole number and it will generate the
// appropriate new div's to overlay the
// current ones:
function update_progress($percent) {
// First let's recreate the percent with
// the new one:
echo "<div class='per'>{$percent}
%</div>\n";
// Now, output a new 'bar', forcing its width
// to 3 times the percent, since we have
// defined the percent bar to be at
// 300 pixels wide.
echo "<div class='bar' style='width: ",
$percent * 3, "px'></div>\n";
// Now, again, force this to be
// immediately displayed:
flush();
}
// Ok, now to use this, first create the
// initial bar info:
create_progress();
// Now, let's simulate doing some various
// amounts of work, and updating the progress
// bar as we go. The usleep commands will
// simulate multiple lines of code
// being executed.
usleep(350000);
update_progress(7);
usleep(1550000);
update_progress(28);
usleep(1000000);
update_progress(48);
usleep(1000000);
update_progress(68);
usleep(150000);
update_progress(71);
usleep(150000);
update_progress(74);
usleep(150000);
update_progress(77);
usleep(1150000);
update_progress(100);
// Now that you are done, you could also
// choose to output whatever final text that
// you might wish to, and/or to redirect
// the user to another page.
?>
Progress bars on web content are hard to get right because you don't know the total time the process will take and you don't have progress indicators from the process to let you know when to update your bar. You might be better off using a spinning loading image like the ones available on ajaxload.com.
You can make a hidden div cover the whole page and activate the div in your javascript when you're waiting.
In your html:
<div style="display:none;" id="wait"></div>
in the css:
#wait {
position:fixed;
top:50%;
left:50%;
background-color:#dbf4f7;
background-image:url('/images/wait.gif'); // path to your wait image
background-repeat:no-repeat;
z-index:100; // so this shows over the rest of your content
/* alpha settings for browsers */
opacity: 0.9;
filter: alpha(opacity=90);
-moz-opacity: 0.9;
}
And then in your JavaScript:
...
$("#wait").show(); // when you want to show the wait image
...
$("#wait").hide(); // when your process is done or don't worry about it if the page is refreshing
You'll need to use Javascript, I recommend you to take a look at JQuery's ProgressBar.

Categories