开发者

Change property on jQuery element

I'm not a very skilled javascript programmer, so i don't know how to do this the correct way.

I have this script

<script type="text/javascript">
    jQuery(function() {  
            jQuery("#brand-select").jMyCarousel({  
                    visible: '100%' ,
            auto: true,
            开发者_如何学运维speed: 1000,
            });
    });

</script>

Which i working properly, but i want to change the property 'auto: true' to 'auto: false' when the mouse is over the ul element 'brand-select'

I want to do something like this (pseudo-code)

jQuery('#brand-select').mouseover(function() {
  brand-select-carousel.auto = false;
});

Does anybody know how to do this?


I have checked your plugin, as the 'auto' property is not exposed to public, so if you want to change this value, you need to modify this plugin.

Add the a public method before 'return this.each(...)' in flie jMyCarousel.js

this.setAuto = function(value){
    if(typeof value != 'boolean' || value == null){
        return;
    o.auto = value;
};

Then you could get instance of jMyCarousel in the constructor and then use it's public method:

var jMyCarouselInstance;
jQuery(function() {  
        jMyCarouselInstance = jQuery("#brand-select").jMyCarousel({  
            visible: '100%' ,
            auto: true,
            speed: 1000,
        });
});
...
jMyCarouselInstance.setAuto(false);


If you want to get or set the property of an element, use the 'attr' api of jquery: http://api.jquery.com/attr/

jQuery('#brand-select').mouseover(function() {
    jQuery(yourSelector).attr('auto', false);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜