http://jsfiddle.net/hL6rT/1/
I've created div with a absolute positioned image inside it the idea is to fade the image in and out like a pulse. All went well until IE8 showed up.
See the link for code. Works fine in FF, that is to say the div fades in and out in a continuous loop. But in IE8 it fades in and out once and then stops.
Works fine in FF & IE8 with mootools 1.2.5, but not 1.3 or 1.3 Compatibility Mode.
For some bizarre reason if the alert after 'fadeIn' is included in the onComplete the function will display the alert and the second alert in the 'fadeOut' onComplete, but still NOT fade the div.
Help?
it is probably easier to do just the tween on the element via the oncomplete to make a blink effect:
http://jsfiddle.net/hL6rT/2/
var fadeImg = document.id('lucy');
fadeImg.set("tween", {
duration: 2000,
transition: Fx.Transitions.Quint.easeIn,
onComplete: function() {
this.element.fade(this.element.getStyle("opacity") == 0 ? 1 : 0);
}
}).fade(0);
// how you can cancel it
document.id("stop").addEvent("click", function(e) {
e.stop();
fadeImg.get("tween").cancel(); // this cancels it.
});
to fix your version:
http://jsfiddle.net/hL6rT/4/
works fine if you set the initial value of opacity to 0
var fadeImg = document.id('lucy').setStyle("opacity", 0);
var fadeIn = function() {
var inDiv = new Fx.Morph(fadeImg, {
link: 'cancel',
duration: 2000,
transition: Fx.Transitions.Quint.easeIn,
onComplete: function() {
fadeOut();
//alert('FadeIn Complete');
}
}).start({
'opacity': ['0', '1']
});
};
var fadeOut = function() {
var outDiv = new Fx.Morph(fadeImg, {
link: 'cancel',
duration: 2000,
transition: Fx.Transitions.Quint.easeOut,
onComplete: function() {
fadeIn();
//alert(FadeOut Complete!');
}
}).start({
'opacity': ['1', '0']
});
};
fadeIn();
update IE does not seem to consistently like this particular transition being chained. you may need to remove it and use the default one.
Related
Normally to make colorbox adjust it's size to the content I use this snippet:
$('#colorbox').colorbox({
onComplete: function () {
$(this).colorbox.resize();
}
});
But this time it does not work, when I try the same thing in an ajax function, after the success response:
$.ajax({
data:number,
dataType: "json",
type:"POST",
url : "payment/request1",
cache: false,
success: function (response) {
console.log(response);
if(response === true){
$.colorbox({html:'<div id="paymentblock"><div><h2 style="color:#444;">Open app in your phone</h2></div><div style="text-align:center;"><p>Payment with '+number+'</p><img src="/images/giphy.gif"></div>'});
$('#edit-commerce-payment-payment-details-number').css('background','#fff').val('');
$('#colorbox').colorbox({
onComplete: function () {
$(this).colorbox.resize();
}
});
}else{
$.colorbox({html:'<div id="paymentblock"><div><h2 style="color:#444;">An error occurred</h2></div><div style="text-align:center;"><p>Kontakta oss.</p></div>'});
$('#colorbox').colorbox({
onComplete: function () {
$(this).colorbox.resize();
}
});
}
}
});
The result is that the colorbox opens with a too small size and don't resize to fit the content. What am I doing wrong?
I created a custom function to resize the colorbox after loading content, after resizing the browser window or, on mobile, after an orientation change that also effectively changes the browser window width.
Modern web design has to deal with widely varying browser widths, especially with so many users on cell phones and tablets, so the content you are loading should be responsive, from about a 320 pixel width on up. Then, let the colorbox size be determined by the available browser width as well as a maximum reasonable size for aesthetic reasons.
This goes in a javascript file included at the bottom of each page:
/* Colorbox resize function */
var resizeTimer;
var resizeColorBox = function() {
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
if ($("#cboxOverlay").is(":visible")) {
$.colorbox.resize({maxWidth:"400px",width:"95%"});
}
}, 300);
};
// Resize Colorbox when resizing window or changing mobile device orientation
$(window).resize(resizeColorBox);
window.addEventListener("orientationchange", resizeColorBox, false);
Then, the colorbox function itself has a few parameters that need to be set correctly. Note that I have closebutton set to false because my HTML content includes a close button that calls the colorbox close function.
$.colorbox({
width:"95%",
maxWidth:400,
maxHeight:"95%",
speed:300,
closeButton:false,
onComplete : function() {
$(this).colorbox.resize({width:"95%",maxWidth:400});
$(window).trigger("resize");
},
html:'Your HTML Here'
});
So, your code need only call the resizeColorBox() function after loading AJAX content and you should be good to go. Plus, it handles other resize situations.
[Edit] If you REALLY need to resize to the width of inner content, then the resize function should first get the width of the container div of the inner content, then resize to that width (possibly plus the width of colorbox padding, etc). In that case, the resize function would be more along the lines of:
var resizeColorBox = function() {
var w = $('content_container').width() + padding_w;
var h = $('content-container').height() + padding_h;
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
if ($("#cboxOverlay").is(":visible")) {
$.colorbox.resize({width:w, height:h});
}
}, 300);
};
Just had this same problem. I dealt with this issue by calling the resize method from inside of page being requested. (May not be possible for you)
Inside the page being called:
<script>
// This resize doesn't respect the maxHeight set when initializing
// So we calculate again, for this example 80%
var maxHeight = parent.innerHeight * 0.8
document.addEventListener('DOMContentLoaded', function(event) {
// Get document height after loaded
var documentHeight = document.documentElement.scrollHeight
// Resize
parent.$.colorbox.resize({
innerHeight: Math.min(documentHeight, maxHeight),
})
})
</script>
Hope this helps someone in the future (or myself if I forget).
I'm using the latest version of jqPlot (v1.0.0b2_r1012) to plot my histograms.
To catch a single click event I'm using 'jqplotDataClick' as follows:
$('#myHistogram').bind('jqplotDataClick', function(ev, seriesIndex, pointIndex, data) {
// Do something
});
Is it possible to catch a double click event instead?
Unfortunately I've been unable to find such event in jqplot.barRenderer.js.
Update:
I've made the following two changes to my jqplot.barRenderer.js file:
Register jqplotDblClick event
$.jqplot.BarRenderer.prototype.init = function(options, plot) {
...
...
plot.postInitHooks.addOnce(postInit);
plot.postDrawHooks.addOnce(postPlotDraw);
plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
plot.eventListenerHooks.addOnce('jqplotDblClick', handleDblClick);
//$.jqplot.eventListenerHooks.push(['jqplotDblClick', handleDblClick]); I've also tried this but without any luck
plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
};
Implement handleDblClick function
function handleDblClick(ev, gridpos, datapos, neighbor, plot) {
if (neighbor) {
var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
var evt = jQuery.Event('jqplotDataDblClick');
evt.pageX = ev.pageX;
evt.pageY = ev.pageY;
plot.target.trigger(evt, ins);
}
}
And then I bind jqplotDataDblClick in my JavaScript file as follows:
$('#myHistogram').bind('jqplotDataDblClick', function(ev, seriesIndex, pointIndex, data) {
alert("Ohayo!"); // Good morning in Japanese
});
However the double click event doensn't get fired when I double click on one of my vertical bar graphs. I've tried binding "jqplotRightClick" but that doesn't work either. If I use "jqplotClick" then everything works as expected.
Does anyone know what I am doing wrong here?
Update 2:
RE: I've tried binding "jqplotRightClick" but that doesn't work either. (see above)
I've just found out that in order to catch this event you have to set the following:
captureRightClick: true,
See: How to capture right click event
From the "cursor" plugin, they handle it like this:
if (c.dblClickReset) {
$.jqplot.eventListenerHooks.push(['jqplotDblClick', handleDblClick]);
}
EDITS
I can capture the double click by just binding the 'jqplotDblClick'. I did not have to push the event. Sorry for the misdirection, my answer above meant to show that the event already existed. See working fiddle here. The only additional thing I added was CSS rules to make the div un-selectable since a double-click will select it.
HTML:
<div id="chart1" style="margin-top:20px; margin-left:20px; width:300px; height:300px; -moz-user-select: -moz-none;-khtml-user-select: none;-webkit-user-select: none;-ms-user-select: none;user-select: none;"></div>
JS:
$(document).ready(function(){
$.jqplot.config.enablePlugins = true;
var s1 = [2, 6, 7, 10];
var ticks = ['a', 'b', 'c', 'd'];
plot1 = $.jqplot('chart1', [s1], {
seriesDefaults:{
renderer:$.jqplot.BarRenderer
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
}
});
$('#chart1').bind('jqplotDblClick',
function (ev, seriesIndex, pointIndex, data) {
alert('hi');
});
});
I've been using JQuery masonry and now I'm adding infinite scroll. There are images in nearly every masonry "brick" and before I was using infinite scroll the images loaded fine and everything was great. I added the next part of the javascript for the infinite scroll and added the imagesLoaded method inside but when the new bricks are appended they come out all piled on top. My assumption is that I am not adding the imagesLoaded method properly in the infinite scroll callback but I haven't been able to find my error. Here's the code
<script type="text/javascript">
$(function(){
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector : '.tile',
columnWidth : 240
});
});
var $container = $('#container');
$container.infinitescroll({
navSelector : ".flickr_pagination",
// selector for the paged navigation (it will be hidden)
nextSelector : "a.next_page",
// selector for the NEXT link (to page 2)
itemSelector : "div.tile"
// selector for all items you'll retrieve
},
// trigger Masonry as a callback
function( newElements ) {
var $newElems = $( newElements );
$container.imagesLoaded(function() {
masonry( 'appended', $newElems );
});
}
);
});
</script>
The first JQuery masonry call works fine and hasn't been touched. It's the second part where there seems to be a problem. Thanks for the help and let me know if you need more information.
Here's the answer
$(function(){
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector : '.tile',
columnWidth : 240
});
});
$container.infinitescroll({
navSelector : '.flickr_pagination', // selector for the paged navigation
nextSelector : 'a.next_page', // selector for the NEXT link (to page 2)
itemSelector : '.tile', // selector for all items you'll retrieve
loading: {
finishedMsg: 'No more pages to load.',
img: 'http://i.imgur.com/6RMhx.gif'
}
},
// trigger Masonry as a callback
function( newElements ) {
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
$container.masonry( 'appended', $newElems, true );
});
}
);
});
The problem was I was calling .imagesLoaded() on $container in the infinite scroll callback function and I should have been calling it on $newElements.
i'm trying to make a rollover of images on a link.
I'm trusting on prototype and scriptaculous.
Check this fiddle: Rollover test
All it's working well except for a strange behavious when you scroll the mouse over the link very very quick or many times.
In that case, the images and link disappears..
This is caused by the 'display:none' status brought by the scriptaculous effects, blocked I mean..
Thanks a lot
You could tyr the afterFinish function like this
Event.observe($('back1'), 'mouseover', function() {
new Effect.Fade('back1', { duration: 0.3,afterFinish:function () {
new Effect.Appear('back2', { duration: 0.3 });
}
});
});
Event.observe($('back2'), 'mouseout', function() {
new Effect.Fade('back2', { duration: 0.3 ,afterFinish:function () {
new Effect.Appear('back1', { duration: 0.3 });
}
});
});
I have a piece of code for showing a picture that slides up from a div when the mouse enters the div, the code works exactly how i want except it bugs when the mouse hovers in and out too quickly and the animation doesn't have time to complete, I've already changed from mouseover and mouseout, to mouseenter and mouseleave and this hasn't seemed to help, any suggestions would be great
<script type="text/javascript">
document.observe("dom:loaded", function() {
var effectInExecution=null;
$('mid_about_us').observe('mouseenter', function() {
if(effectInExecution) effectInExecution.cancel();
effectInExecution=new Effect.SlideDown('about_us_mo',{style:'height:140px;', duration: 1.0 });
});
$('mid_about_us').observe('mouseleave', function() {
if(effectInExecution) effectInExecution.cancel();
effectInExecution=new Effect.SlideUp('about_us_mo',{style:'height:0px;', duration: 1.0 });
});
});
I wrote a Prototype class a while back to solve this problem, the issue can be fixed by supplying a scope parameter to the effect options. anyway here is the class i wrote:
var DivSlider = Class.create();
Object.extend(DivSlider, {
toggle: function(selector, element, options) {
element = $(element);
this.options = Object.extend({
duration: 0.5,
fps: 35,
scope: 'DivSlider',
forceOpen: false
}, options || {});
var toggle = element.visible();
if (toggle && this.options.forceOpen) {
//already open, leave.. still call callback
(this.options.after || Prototype.emptyFunction)
.bind(this, element)();
return;
}
var effects = new Array();
if (toggle) {
effects.push(new Effect.SlideUp(element, {
sync: true
}));
} else {
$$(selector).each(function(el) {
if ((element !== el) && el.visible()) {
effects.push(new Effect.SlideUp(el, {
sync: true
}));
}
});
effects.push(new Effect.SlideDown(element, {
sync: true
}));
}
new Effect.Parallel(effects, {
duration: this.options.duration,
fps: this.options.fps,
queue: {
position: 'end',
scope: this.options.scope
},
beforeStart: function() {
(this.options.before || Prototype.emptyFunction)
.bind(this, element)();
}.bind(this),
afterFinish: function() {
(this.options.after || Prototype.emptyFunction)
.bind(this, element)();
}.bind(this)
});
}
});
and to use it in your case you would simply use:
DivSlider.toggle('div.your_class', your_id);
in your enter/leave code, it can handle multiple div's of the same class also, allowing only one div per class to be open at any single time. If this does not fit your needs you can easily deconstruct the class to get the code you actually need.