我需要一些帮助来实现一个旋转报价 jquery 插件。
这是Jquery代码:
(function($) {
$.fn.quovolver = function(speed, delay) {
/* Sets default values */
if (!speed) speed = 500;
if (!delay) delay = 6000;
// If "delay" is less than 4 times the "speed", it will break the effect
// If that's the case, make "delay" exactly 4 times "speed"
var quaSpd = (speed*4);
if (quaSpd > (delay)) delay = quaSpd;
// Create the variables needed
var quote = $(this),
firstQuo = $(this).filter(':first'),
lastQuo = $(this).filter(':last'),
wrapElem = '<div id="quote_wrap"></div>';
// Wrap the quotes
$(this).wrapAll(wrapElem);
// Hide all the quotes, then show the first
$(this).hide();
$(firstQuo).show();
// Set the hight of the wrapper
$(this).parent().css({height: $(firstQuo).height()});
// Where the magic happens
setInterval(function(){
// Set required hight and element in variables for animation
if($(lastQuo).is(':visible')) {
var nextElem = $(firstQuo);
var wrapHeight = $(nextElem).height();
} else {
var nextElem = $(quote).filter(':visible').next();
var wrapHeight = $(nextElem).height();
}
// Fadeout the quote that is currently visible
$(quote).filter(':visible').fadeOut(speed);
// Set the wrapper to the hight of the next element, then fade that element in
setTimeout(function() {
$(quote).parent().animate({height: wrapHeight}, speed);
}, speed);
if($(lastQuo).is(':visible')) {
setTimeout(function() {
$(firstQuo).fadeIn(speed*2);
}, speed*2);
} else {
setTimeout(function() {
$(nextElem).fadeIn(speed);
}, speed*2);
}
}, delay);
};
})(jQuery);
我已将此代码保存为我网站中的 JS 文件
这是我的 HTML:
<link rel="stylesheet" media="screen" type="text/css" href="../../style.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.quovolver.js"></script>
<body>
<div>
I want my rotating quotes HERE
</div>
</body>
</html>
有人告诉我“使用这行代码调用文档就绪函数中的脚本:$(’element’).quovolver();
”
我的问题是,我在哪里以及如何存储我的引号,以及如何在我在 html 页面中注明的空间中调用这个 Jquery 插件?
谢谢你的帮助!!