HTML5自定义元素播放焦点图动画的实现

2020-04-24 19:05:00易采站长站整理

$el.css("left", function(current){
return current + windowWidth - frameLeft;
});

setTimeout(function(){
$el.animate({left: final, opacity: 1}, options.speed, options.easing, function(){
dfr.resolve();
});
}, options.delay);

return dfr.promise();
}

// two pass function that first iterates all the elements and gets their position/width/height
// and then sets their position to absolute
function absolutize($elements) {

// todo - move it to separate function and do it just once
// gather the original position/dimension data for all elements
$elements.each(function(){
var $t = $(this);

if ($t.data("tlrkOriginalPos")) return

$t.data("tlrkOriginalPos", {
position: $t.position(),
width: $t.width(),
height: $t.height(),
css_pos: $t.css("position"),
css_left: $t.css("left"),
css_top: $t.css("top"),
css_width: $t.css("width") || "auto",
css_height: $t.css("height") || "auto"
});

});

// set the absolute position
$elements.each(function(){
var $t = $(this),
opos = $t.data("tlrkOriginalPos");

$t.css({
position: "absolute",
left: opos.position.left,
top: opos.position.top,
width: opos.width,
height: opos.height
});
});
}

function restoreFrameElements($elements) {
$elements.each(function(){
var $t = $(this),
opos = $t.data("tlrkOriginalPos");

if (!opos) return

$t.css({
position: opos.css_pos,
left: opos.css_left,
top: opos.css_top,
width: opos.css_width,
height: opos.css_height
});
});

}

var TlrkSlider = function( elem, options ){
this.elem = elem;
this.$elem = $(elem);
this.options = options;
};

// the plugin prototype
TlrkSlider.prototype = {
defaults: {

defaultElementOptions: {
speed: 1200,
easing: "easeInOutBack",
// interval before the element starts moving when the fadeIn/Out functions are called
// it's a good idea to give different delays for the different elements
// if all have the same delay they'll start moving all together
delay: 100
},

// dispose elements are these that are not included in the elements object
// but affect the document flow and will be fadedIn/Out
disposeDelay: 100, // delay for the dispose elements
disposeSpeed: 1000, // how quickly they'll fadeOut/In

delayBetweenTransition: 1000, // time between starting fadeOut and fadeIn
delayAnimation: 7000, // time between auto changing the current frame

loop: true, // if true when clicking next on the last frame the slider jumps to the first one

autoStart: true, // start the automatic looping through the frames on init

framesSelector: "section", // selector for the frames inside the slider