Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
shuffle slider display
Old 04-04-2011, 10:00 AM shuffle slider display
Novice Talker

Posts: 5
Trades: 0
hello,

i have a problem on the slider of my site, though the slider works fine and good but i need it to be random or shuffle instead of displaying an ordered content.. i already have the code and it need some modification.

this is the line on the main file.php
Code:
<script type="text/javascript">
$(document).ready(function() {
    $('#slider1').s3Slider({

        timeOut: 8000

    });
});
</script>

<div id="slider1">
    <ul id="slider1Content">
        <li class="slider1Image">
            <a href="goo.com"><img src="products/1.png" alt="1" /></a>
            <span class="left">
            caption1 
            </span>
        </li>

        <li class="slider1Image">
            <a href=""><img src="products/2.png" alt="2" /></a>
            <span class="right">caption2
            </span>
        </li>

        <li class="slider1Image">
            <a href=""><img src="products/3.png" alt="3" /></a>
            <span class="right">caption3. 
            </span>
        </li></div>
this is the java script file
Code:
(function($){  

$.fn.s3Slider = function(vars) {       



    var element     = this;
    var timeOut     = (vars.timeOut != undefined) ? vars.timeOut : 4000;
    var current     = null;
    var timeOutFn   = null;
    var faderStat   = true;
    var mOver       = false;
    var items       = $("#" + element[0].id + "Content ." + element[0].id + "Image");
    var itemsSpan   = $("#" + element[0].id + "Content ." + element[0].id + "Image span");

    items.each(function(i) {

        $(items[i]).mouseover(function() {
           mOver = true;
        });

        $(items[i]).mouseout(function() {
            mOver   = false;
            fadeElement(true);

        });

    });

    var fadeElement = function(isMouseOut) {
        var thisTimeOut = (isMouseOut) ? (timeOut/2) : timeOut;
        thisTimeOut = (faderStat) ? 10 : thisTimeOut;
        if(items.length > 0) {
            timeOutFn = setTimeout(makeSlider, thisTimeOut);
        } else {
            console.log("Poof..");
        }
    }

    var makeSlider = function() {

        current = (current != null) ? current : items[(items.length-1)];
        var currNo      = jQuery.inArray(current, items) + 1
        currNo = (currNo == items.length) ? 0 : (currNo - 1);
        var newMargin   = $(element).width() * currNo;
        if(faderStat == true)

        {
            if(!mOver) {
                $(items[currNo]).fadeIn((timeOut/6), function() {
                    if($(itemsSpan[currNo]).css('bottom') == 0) {
                        $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                            faderStat = false;
                            current = items[currNo];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    } else {
                        $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                            faderStat = false;
                            current = items[currNo];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    }
                });
            }
        } else {
            if(!mOver) {
                if($(itemsSpan[currNo]).css('bottom') == 0) {
                    $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                        $(items[currNo]).fadeOut((timeOut/6), function() {
                            faderStat = true;
                            current = items[(currNo+1)];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    });
                } else {
                    $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                    $(items[currNo]).fadeOut((timeOut/6), function() {
                            faderStat = true;
                            current = items[(currNo+1)];
                            if(!mOver) {
                                fadeElement(false);
                            }
                        });
                    });
                }
            }
        }
    }

    makeSlider();

};})(jQuery);
i am struggling modifying this script for almost a week ... please help
ericbon is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-06-2011, 07:52 AM Re: shuffle slider display
Extreme Talker

Posts: 246
Trades: 0
Look for these lines:

var currNo = jQuery.inArray(current, items) + 1
currNo = (currNo == items.length) ? 0 : (currNo - 1);

and change it to the following:

var currNo = randomNumber(items.length);

Add a function to the plugin for creating random numbers:

function randomNumber(max) {
if (!seed) {
seed = new Date().getTime();
}
else {
seed++;
}

seed = (seed * 9301 + 49297) % 233280;

return Math.floor(seed / (233280.0) * max);
}



Hopefully this works, didn't really test it.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to shuffle slider display
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10552 seconds with 12 queries