我環顧四周,但沒有找到任何東西,請參閱下面的代碼。暫停jQuery懸停(鼠標懸停)
考慮到這一點,我只需要能夠在鼠標懸停時暫停動畫。
感謝您的幫助!
(function ($) {
\t $.fn.textSlider = function (options) {
\t \t /* Default settings */
\t \t var settings = $.extend(
\t \t \t {
\t \t \t \t timeout: 2000,
\t \t \t \t slideTime: 750,
\t \t \t },
\t \t \t options
\t \t);
\t \t var nextItem;
\t \t var currentItem = 0;
\t \t var count = 0;
\t \t this.children('.slider-item').each(
\t \t \t function()
\t \t \t {
\t \t \t \t $(this).addClass('slide-' + (count))
\t \t \t \t \t .css(
\t \t \t \t \t \t {
\t \t \t \t \t \t \t //opacity: \t 0,
\t \t \t \t \t \t \t //paddingTop: \t '100px',
\t \t \t \t \t \t \t //paddingBottom: '0px'
\t \t \t \t \t \t }
\t \t \t \t \t);
\t \t \t \t $(this).hide();
\t \t \t \t count++;
\t \t \t }
\t \t);
\t \t function firstSlide()
\t \t {
\t \t \t $('.slide-' + currentItem).show().animate({
\t \t \t \t //paddingTop: '0px', paddingBottom: '50px',
\t \t \t \t opacity: 1 }, settings.slideTime);
\t \t \t setTimeout (transition, settings.timeout);
\t \t }
\t \t function transition()
\t \t {
\t \t \t nextItem = parseInt (currentItem + 1);
\t \t \t if (nextItem >= count)
\t \t \t \t nextItem = 0;
\t \t \t $('.slide-' + currentItem).animate({
\t \t \t \t //paddingTop: '100px', paddingBottom: '0px',
\t \t \t \t opacity: 0 }, settings.slideTime, function() {
\t \t \t \t \t $(this).hide();
\t \t \t \t \t $('.slide-' + nextItem).show().animate({
\t \t \t \t \t \t //paddingTop: '0px', paddingBottom: '50px',
\t \t \t \t \t \t opacity: 1 }, settings.slideTime);
\t \t \t });
\t \t \t currentItem = nextItem;
\t \t \t setTimeout (transition, settings.timeout);
\t \t }
\t \t return firstSlide();
\t };
}(jQuery));
// Start the Text Slider
\t $('.slide').textSlider({
\t \t timeout: 5000,
\t \t slideTime: 650,
\t \t loop: 1
\t });
/* Main Message & Text */
.main-message {
\t font-size: 150%;
\t font-weight: bold;
\t padding-bottom: 20px;
\t margin-left: 20px;
}
.main-text {
\t font-size: 110%;
\t margin-left: 20px;
}
<!-- Start Text Slider -->
\t \t <div class="slide">
\t \t \t <div class="slider-item">
\t \t \t \t <div class="main-message">Test 1</div>
\t \t \t \t <div class="main-text">Sub text here 1</div>
\t \t \t </div>
\t \t \t <div class="slider-item">
\t \t \t \t <div class="main-message">Test 2</div>
\t \t \t \t <div class="main-text">Sub text here 2</div>
\t \t \t </div>
\t \t \t <div class="slider-item">
\t \t \t \t <div class="main-message">Test 3</div>
\t \t \t \t <div class="main-text">Sub text here 3</div>
\t \t \t </div>
\t \t </div>
\t \t <!-- End Text Slider -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
謝謝,這工作!我最想添加的最後一件事是在文本底部的子彈導航,以便從一個文本滾動到另一個文本。但是否則這是非常好的:D –
@LuisM非常感謝。對於子彈你需要做出更多的變化:自動播放:開/關,步驟... – gaetanoM
@LuisM對於子彈,你可以採取lokk [純CSS滑塊 - 自動播放,kenburns,prev/next,子彈 - 沒有js !](https://codepen.io/hw/pen/biEBz) – gaetanoM