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

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

"position" can have one of the following values:
"next", "prev", "first", "last", "+1", "-1" or a numeric value

to start/stop the automatic loop:
$("#slider").tlrkSlider("start");
$("#slider").tlrkSlider("stop");

to change the delay between automatic transitions:
$("#slider").tlrkSlider("option", "delayAnimation", 1000);

to change any option:
$("#slider").tlrkSlider("option", option_name, option_value);

Changing the "elements" object is not tested.

Changing the following options: "navigation", "navigationClass", "framesSelector", "autoStart" won't have any effect for now.
They are used only during the initialization.

$("#slider").data("tlrkSlider") will return the plugin instance and the methods/properties can be accessed from there.

The plugin contructor defaults are accessable through TlrkSlider.defaults

The function that actually sweep the elements in/out can be overriden from
TlrkSlider.prototype._animationIn and TlrkSlider.prototype._animationOut

See sweepIn/sweepOut

*/

;(function( $, window, document, undefined ){

// utility function that generates the "dots" navigation
function generateNavigation($el, count, config) {
var i, html = "",
width = count * 24;

html += "<ol class='" + config.navigationClass + "' style='margin-left: -" + width/2 + "px; width: " + width + "px'>";
for (i = 0; i < count; i++) {
html += "<li><a " + (i === 0 ? "class='selected'" : "" ) + " href='#" + (i) + "'>slide</a></li>";
}
html += "</ol>";

$el.append(html);
}

function sweepOut($el, windowWidth) {
var dfr = $.Deferred(),
pos = $el.position(),
width = $el.width(),
delta, final,
options = $el.data("tlrkAnimOptions");

windowWidth = windowWidth || $(window).width(); // check if the windowWidth is passed, if not - get it

delta = windowWidth - pos.left;
final = -(delta);

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

return dfr.promise();
}

function sweepIn($el, windowWidth, frameLeft) {
var dfr = $.Deferred(),
options = $el.data("tlrkAnimOptions"),
positionData = $el.data("tlrkOriginalPos"),
final = positionData.position.left,
rightEdge;

windowWidth = windowWidth || $(window).width(); // check if the windowWidth is passed, if not - get it

$el.css({opacity: 0, display: "block"}); // move it outside the right edge of the screen