Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-09-2013, 11:06 AM   PM User | #1
vickya819
New to the CF scene

 
Join Date: Mar 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vickya819 is an unknown quantity at this point
Post I have my own image slider but iam unable to run it automatically so pleas help me.

PHP Code:
(function($) { 

var 
types = ['DOMMouseScroll''mousewheel'];
 var 
autoplay 4000;
 if (
autoplay) { setTimeout(function() { nextimage(true); }, 4000); }
if ($.
event.fixHooks) {
    for ( var 
i=types.lengthi; ) {
        $.
event.fixHookstypes[--i] ] = $.event.mouseHooks;
    }
}

$.
event.special.mousewheel = {
    
setup: function() {
        if ( 
this.addEventListener ) {
            for ( var 
i=types.lengthi; ) {
                
this.addEventListenertypes[--i], handlerfalse );
            }
        } else {
            
this.onmousewheel handler;
        }
    },
    
    
teardown: function() {
        if ( 
this.removeEventListener ) {
            for ( var 
i=types.lengthi; ) {
                
this.removeEventListenertypes[--i], handlerfalse );
            }
        } else {
            
this.onmousewheel null;
        }
    }
};

$.
fn.extend({
    
mousewheel: function(fn) {
        return 
fn this.bind("mousewheel"fn) : this.trigger("mousewheel");
    },
    
    
unmousewheel: function(fn) {
        return 
this.unbind("mousewheel"fn);
    }
});


function 
handler(event) {
    var 
orgEvent event || window.eventargs = [].slice.callarguments), delta 0returnValue truedeltaX 0deltaY 0;
    
event = $.event.fix(orgEvent);
    
event.type "mousewheel";
    
    
// Old school scrollwheel delta
    
if ( orgEvent.wheelDelta ) { delta orgEvent.wheelDelta/120; }
    if ( 
orgEvent.detail     ) { delta = -orgEvent.detail/3; }
    
    
// New school multidimensional scroll (touchpads) deltas
    
deltaY delta;
    
    
// Gecko
    
if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
        
deltaY 0;
        
deltaX = -1*delta;
    }
    
    
// Webkit
    
if ( orgEvent.wheelDeltaY !== undefined ) { deltaY orgEvent.wheelDeltaY/120; }
    if ( 
orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }
    
    
// Add event and delta to the front of the arguments
    
args.unshift(eventdeltadeltaXdeltaY);
    
    return ($.
event.dispatch || $.event.handle).apply(thisargs);
}

})(
jQuery);

/**
 * @version        2.0
 * @package        jquery
 * @subpackage    lofslidernews
 * @copyright    Copyright (C) JAN 2010 LandOfCoder.com <@emai:landofcoder@gmail.com>. All rights reserved.
 * @website     [url]http://landofcoder.com[/url]
 * @license        This plugin is dual-licensed under the GNU General Public License and the MIT License 
 */
// JavaScript Document
(function($) {
     $.
fn.lofJSidernews = function( settings ) {
         return 
this.each(function() {
            
// get instance of the lofSiderNew.
            
new  $.lofSidernewsthissettings ); 
        });
      }
     $.
lofSidernews = function( objsettings ){
        
this.settings = {
            
direction            '',
            
mainItemSelector    'li',
            
navInnerSelector    'ul',
            
navSelector          'li' ,
            
navigatorEvent        'click'/* click|mouseenter */,
            
wapperSelector:     '.sliders-wrap-inner',
            
interval               5000,
            
auto                false// whether to automatic play the slideshow
            
maxItemDisplay         3,
            
startItem            0,
            
navPosition            'vertical',/* values: horizontal|vertical*/ 
            
navigatorHeight        100,
            
navigatorWidth        310,
            
duration            600,
            
navItemsSelector    '.navigator-wrap-inner li',
            
navOuterSelector    '.navigator-wrapper' ,
            
isPreloaded            true,
            
easing                'easeInOutQuad',
            
onPlaySlider:function(objslider){},
            
onComplete:function(sliderindex){  }
        }    
        $.
extendthis.settingssettings ||{} );    
        
this.nextNo         null;
        
this.previousNo     null;
        
this.maxWidth  this.settings.mainWidth || 684;
        
        

        
this.wrapper = $( obj ).findthis.settings.wapperSelector );    
        var 
wrapOuter = $('<div class="sliders-wrapper"></div>').widththis.maxWidth );
        
this.wrapper.wrapwrapOuter );
        
        
this.slides this.wrapper.findthis.settings.mainItemSelector ); 
        if( !
this.wrapper.length || !this.slides.length ) return ;
        
// set width of wapper
        
if( this.settings.maxItemDisplay this.slides.length ){
            
this.settings.maxItemDisplay this.slides.length;    
        }
        
this.currentNo      isNaN(this.settings.startItem)||this.settings.startItem this.slides.length?0:this.settings.startItem;
        
this.navigatorOuter = $( obj ).findthis.settings.navOuterSelector );    
        
this.navigatorItems = $( obj ).findthis.settings.navItemsSelector ) ;
        
this.navigatorInner this.navigatorOuter.findthis.settings.navInnerSelector );
        
// if use automactic calculate width of navigator
        
         
if( this.settings.navigatorHeight == null || this.settings.navigatorWidth == null ){
            
this.settings.navigatorHeight this.navigatorItems.eq(0).outerWidth(true);
            
this.settings.navigatorWidth this.navigatorItems.eq(0).outerHeight(true);
            
        }
        if( 
this.settings.navPosition == 'horizontal' ){ 
            
this.navigatorInner.widththis.slides.length this.settings.navigatorWidth );
            
this.navigatorOuter.widththis.settings.maxItemDisplay this.settings.navigatorWidth );
            
this.navigatorOuter.height(    this.settings.navigatorHeight );
            
        } else {
            
this.navigatorInner.heightthis.slides.length this.settings.navigatorHeight );    
            
            
this.navigatorOuter.heightthis.settings.maxItemDisplay this.settings.navigatorHeight );
            
this.navigatorOuter.width(    this.settings.navigatorWidth );
        }        
        
this.slides.widththis.settings.mainWidth );    
        
this.navigratorStep this.__getPositionModethis.settings.navPosition );         
        
this.directionMode this.__getDirectionMode();  
        
        
        if( 
this.settings.direction == 'opacity') {
            
this.wrapper.addClass'lof-opacity' );
            $(
this.slides).css({'opacity':0,'z-index':1}).eq(this.currentNo).css({'opacity':1,'z-index':3});
        } else { 
            
this.wrapper.css({'left':'-'+this.currentNo*this.maxSize+'px''width':( this.maxWidth ) * this.slides.length } );
        }

        
        if( 
this.settings.isPreloaded ) {
            
this.preLoadImagethis.onComplete );
        } else {
            
this.onComplete();
        }
        
        
$buttonControl = $( ".button-control"obj);
        if( 
this.settings.auto ){
            
$buttonControl.addClass("action-stop");
        } else {
            
$buttonControl.addClass("action-start");
        }
        var 
self this;
        
        $( 
obj ).hover(function(){
                
self.stop();    
                
$buttonControl.addClass("action-start").removeClass("action-stop").addClass("hover-stop");
        }, function(){
            if( 
$buttonControl.hasClass("hover-stop") ){
        
                if(    
self.settings.auto ){
                    
$buttonControl.removeClass("action-start").removeClass("hover-stop").addClass("action-stop");
                    
self.playself.settings.interval,'next'true );        
                }
            }
        } );
        
        
        
$buttonControl.click( function() {
            if( 
$buttonControl.hasClass("action-start") ){
                
self.settings.auto =true;
                
self.playself.settings.interval,'next'true );
                
$buttonControl.removeClass("action-start").addClass("action-stop");
            } else{
                
self.settings.auto =false;
                
self.stop();    
                
$buttonControl.addClass("action-start").removeClass("action-stop");
            }
        } );
     }
     $.
lofSidernews.fn =  $.lofSidernews.prototype;
     $.
lofSidernews.fn.extend =  $.lofSidernews.extend = $.extend;
     
     $.
lofSidernews.fn.extend({
                              
        
startUp:function( objwrapper ) {
            
seft this;

            
this.navigatorItems.each( function(indexitem ){
                $(
item).bindseft.settings.navigatorEvent,( function(){
                    
seft.jumpingindextrue );
                    
seft.setNavActiveindexitem );                    
                } ));
                $(
item).css( {'height'seft.settings.navigatorHeight'width':  seft.settings.navigatorWidth} );
            })
            
this.registerWheelHandlerthis.navigatorOuterthis );
            
this.setNavActivethis.currentNo );
            
this.settings.onCompletethis.slides.eq(this.currentNo ),this.currentNo  );
            if( 
this.settings.buttons && typeof (this.settings.buttons) == "object" ){
                
this.registerButtonsControl'click'this.settings.buttonsthis );

            }
            if( 
this.settings.auto 
            
this.playthis.settings.interval,'next'true );
            
            return 
this;
        },
        
onComplete:function(){
            
setTimeout( function(){ $('.preload').fadeOut900, function(){  $('.preload').remove(); } ); }, 400 );    this.startUp( );
        },
        
preLoadImage:function(  callback ){
            var 
self this;
            var 
images this.wrapper.find'img' );
    
            var 
count 0;
            
images.each( function(index,image){ 
                if( !
image.complete ){                  
                    
image.onload =function(){
                        
count++;
                        if( 
count >= images.length ){
                            
self.onComplete();
                        }
                    }
                    
image.onerror =function(){ 
                        
count++;
                        if( 
count >= images.length ){
                            
self.onComplete();
                        }    
                    }
                }else {
                    
count++;
                    if( 
count >= images.length ){
                        
self.onComplete();
                    }    
                }
            } );
        },
        
navivationAnimate:function( currentIndex ) { 
            if (
currentIndex <= this.settings.startItem 
                
|| currentIndex this.settings.startItem >= this.settings.maxItemDisplay-1) {
                    
this.settings.startItem currentIndex this.settings.maxItemDisplay+2;
                    if (
this.settings.startItem 0this.settings.startItem 0;
                    if (
this.settings.startItem >this.slides.length-this.settings.maxItemDisplay) {
                        
this.settings.startItem this.slides.length-this.settings.maxItemDisplay;
                    }
            }        
        
            
this.navigatorInner.stop().animate( eval('({'+this.navigratorStep[0]+':-'+this.settings.startItem*this.navigratorStep[1]+'})'), 
                                                {
duration:500easing:'easeInOutQuad'} );    
        },
        
setNavActive:function( indexitem ){
            if( (
this.navigatorItems) ){ 
                
this.navigatorItems.removeClass'active' );
                $(
this.navigatorItems.get(index)).addClass'active' );    
                
this.navivationAnimatethis.currentNo );    
            }
        },
        
__getPositionMode:function( position ){
            if(    
position  == 'horizontal' ){
                return [
'left'this.settings.navigatorWidth];
            }
            return [
'top'this.settings.navigatorHeight];
        },
        
__getDirectionMode:function(){
            switch( 
this.settings.direction ){
                case 
'opacity'this.maxSize=0; return ['opacity','opacity'];
                default: 
this.maxSize=this.maxWidth; return ['left','width'];
            }
        },
        
registerWheelHandler:function( elementobj ){ 
             
element.bind('mousewheel', function(eventdelta ) {
                var 
dir delta 'Up' 'Down',
                    
vel Math.abs(delta);
                if( 
delta ){
                    
obj.previoustrue );
                } else {
                    
obj.nexttrue );
                }
                return 
false;
            });
        },
        
registerButtonsControl:function( eventHandlerobjectsself ){ 
            for( var 
action in objects ){ 
                switch (
action.toString() ){
                    case 
'next':
                        
objects[action].click( function() { self.nexttrue) } );
                        break;
                    case 
'previous':
                        
objects[action].click( function() { self.previoustrue) } );
                        break;
                }
            }
            return 
this;    
        },
        
onProcessing:function( manualstartend ){             
            
this.previousNo this.currentNo + (this.currentNo>? -this.slides.length-1);
            
this.nextNo     this.currentNo + (this.currentNo this.slides.length-1this.slides.length);                
            return 
this;
        },
        
finishFx:function( manual ){
            if( 
manual this.stop();
            if( 
manual && this.settings.auto ){ 
                
this.playthis.settings.interval,'next'true );
            }        
            
this.setNavActivethis.currentNo );
            
this.settings.onPlaySliderthis, $(this.slides).eq(this.currentNo) );
        },
        
getObjectDirection:function( startend ){
            return eval(
"({'"+this.directionMode[0]+"':-"+(this.currentNo*start)+"})");    
        },
        
fxStart:function( indexobjcurrentObj ){
                var 
this;
                if( 
this.settings.direction == 'opacity' ) { 
                    
                    $(
this.slides).stop().animate({opacity:0}, {durationthis.settings.durationeasing:this.settings.easing,complete:function(){ 
                                                                                    
s.slides.css("z-index","1")
                                                                                    
s.slides.eq(index).css("z-index","3");                                                            
                                                                                        }} );
                    $(
this.slides).eq(index).stop().animate( {opacity:1}, { duration this.settings.duration
                                                                            
easing   :this.settings.easing,
                                                                            
complete :function(){ s.settings.onComplete($(s.slides).eq(index),index); }} );
                }else {
                    
this.wrapper.stop().animateobj, {durationthis.settings.durationeasing:this.settings.easing,complete:function(){ 
                                                                                                        
s.settings.onComplete($(s.slides).eq(index),index)                                   
                                                                                                    } } );
                }
            return 
this;
        },
        
jumping:function( nomanual ){
            
this.stop(); 
            if( 
this.currentNo == no ) return;        
             var 
obj = eval("({'"+this.directionMode[0]+"':-"+(this.maxSize*no)+"})");
            
this.onProcessingnullmanual0this.maxSize )
                .
fxStartnoobjthis )
                .
finishFxmanual );    
                
this.currentNo  no;
        },
        
next:function( manual item){

            
this.currentNo += (this.currentNo this.slides.length-1) ? : (this.slides.length);    
            
this.onProcessingitemmanual0this.maxSize )
                .
fxStartthis.currentNothis.getObjectDirection(this.maxSize ), this )
                .
finishFxmanual );
        },
        
previous:function( manualitem ){
            
this.currentNo += this.currentNo ? -this.slides.length 1;
            
this.onProcessingitemmanual )
                .
fxStartthis.currentNothis.getObjectDirection(this.maxSize ), this )
                .
finishFxmanual    );            
        },
        
play:function( delaydirectionwait ){    
            
this.stop(); 
            if(!
wait){ this[direction](false); }
            var 
self  this;
            
this.isRun setTimeout(function() { self[direction](true); }, delay);
        },
        
stop:function(){ 
            if (
this.isRun == null) return;
            
clearTimeout(this.isRun);
            
this.isRun null
        }
    })
})(
jQuery

Last edited by VIPStephan; 03-10-2013 at 03:00 PM.. Reason: added code BB tags
vickya819 is offline   Reply With Quote
Old 03-10-2013, 03:03 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,600
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
If you post any code please put it in between [CODE][/CODE] tags. It makes scanning your posts much easier and people are more likely to reply if they don’t have to scroll forever through a huge pile of dense characters. You can do this by clicking the small ‘#’ icon above the reply field.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Tags
image slider

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 07:46 AM.


Advertisement
Log in to turn off these ads.