I've written this jQuery plugin, but it just won't work in Opera (I'm using 11.51). It works fine in all other browsers, even IE7, so this has really got me stumped.
Any help much appreciated, thanks.
(function($) {
$.fn.toggleBox = function(options) {
var opts = $.extend({}, $.fn.toggleBox.defaults, options);
return this.each(function() {
var $this = $(this);
var target;
$this.click(function(ev) {
ev.preventDefault();
$(target).stop(1,1).slideToggle(opts.speed, 'swing', function() {
开发者_运维问答 $(target).animate({'opacity': 1});
});
}).hover(
function(){
$(target).stop(1,1).animate({'opacity': 0.4});
},
function(){
$(target).stop(1,1).animate({'opacity': 1});
}
)
.each(function(){
$(this).css('cursor', 'pointer');
target = $(this).attr('data-toggler');
target = $('[data-toggle-content=' + target + ']');
if ( $(this).attr('data-toggler-state') == 'open') {
$(target).show();
} else {
$(target).hide();
}
});
});
};
// Default settings for the plugin
$.fn.toggleBox.defaults = {
speed: 500
};
})(jQuery);
$('[data-toggler]').toggleBox();
// end toggler
Following is the html markup used for a toggler and it's content:
<div data-toggler="togglerID"> Click to toggle content</div>
<div data-toggle-content="togglerID"> Toggler content </div>
=========== EDIT ===========
Well that figures... as soon as I post the question, I figure it out.
I needed to change the last line where I call the plugin to run at domReady:
jQuery(function ($) { $('[data-toggler]').toggleBox(); });
Works fine in Opera now.
I guess you came across the bug that made me break the BBC iPlayer, namely that a dynamically inserted script in Opera doesn't get to "see" content after the script that added it? (Unless you use jQuery's $(document).ready()
or similar).
精彩评论