Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
动态样式-使用JavaScript操作CSS_Javascript_Css - Fatal编程技术网

动态样式-使用JavaScript操作CSS

动态样式-使用JavaScript操作CSS,javascript,css,Javascript,Css,我在worpress主题中有一个图像滑块,它当前使用内联样式将显示从“块”更改为“无”,具体取决于它是哪个幻灯片。有没有一种方法可以将其分离,以便它在js中动态更改,而不是使用内联样式?当它成为当前幻灯片时,它将更改为显示块 html: 脚本:我是js新手,所以非常感谢您的帮助。我肯定不是所有这些都适用,但我想包括它,以便您可以看到它 <script type="text/javascript"> /* <![CDATA[ */ jQuery(document).ready

我在worpress主题中有一个图像滑块,它当前使用内联样式将显示从“块”更改为“无”,具体取决于它是哪个幻灯片。有没有一种方法可以将其分离,以便它在js中动态更改,而不是使用内联样式?当它成为当前幻灯片时,它将更改为显示块

html:

脚本:我是js新手,所以非常感谢您的帮助。我肯定不是所有这些都适用,但我想包括它,以便您可以看到它

<script type="text/javascript">
/* <![CDATA[ */


jQuery(document).ready(function(){

    // Add class nopreload to all images in 'slide_content' div
    if( jQuery('.slide_content').length>0 ) {
        jQuery('.slide_content').find('img').addClass('nopreload');
    }

            jQuery('#fading_slides').preloader({
            imgAppend: '.load_slide_image',
            fade: false,
            slider: true,
            onDone: function(){
                jQuery('#slider_module .mysite_preloader_large').remove();
                jQuery('.slider_nav').tabs('#fading_slides > div.single_fading_slide', {
                    effect: 'fade',
                    fadeInSpeed: 'fast',
                    rotate: true,
                    onBeforeClick : function(event,index) {
                        if(this.getPanes().eq(index).children().eq(0).find('.vimeo_video').length>0) {
                            var vimeo_video = this.getPanes().eq(index).children().eq(0).find('.vimeo_video').parent().html();
                            this.getPanes().eq(index).children().eq(0).find('.vimeo_video').parent().empty().html(vimeo_video);
                            jQuery('.vimeo_video').each(function(index, vimeo_video){
                                Froogaloop.init([vimeo_video]);
                                vimeo_video.addEvent('onLoad', VimeoEmbed.vimeo_player_loaded);
                            });
                        }
                        if(this.getPanes().eq(index).children().eq(0).find('.youtube_video').length>0) {
                            var vimeo_video = this.getPanes().eq(index).children().eq(0).find('.youtube_video').parent().html();
                            this.getPanes().eq(index).children().eq(0).find('.youtube_video').parent().empty().html(vimeo_video);
                            jQuery('.youtube_video').each(function(index, youtube_video){
                                onYouTubePlayerAPIReady(youtube_video.id);
                            });
                        }
                        _class = this.getPanes().eq(index).attr('class');
                        jQuery('#slider_module_inner').removeClass();
                        jQuery('#slider_module_inner').addClass( _class.replace('single_fading_slide ', '') );

                        if(this.getPanes().eq(index).children().eq(0).find('.vimeo_video').length>0 && typeof navScript != 'undefined'){
                            setTimeout(function(){
                                jQuery('.slider_nav_thumb .slider_nav').animate({opacity:0},300);
                                jQuery('.slider_nav_thumb .slider_nav').animate({height:'0px'},300);
                              }, 1000 );
                        }
                    },
                    onClick : function(event,index) {}

                }).slideshow({clickable:false, autoplay:true, interval:4000, autopause:true});
                jQuery('#fading_slides').removeClass('noscript');
                jQuery('.slider_nav').removeClass('noscript');
            }
        });


});
/* ]]> */
</script>
非常感谢你的帮助

您可以使用jQuery的.show和.hide来处理此问题:

$('#selector').show();
$('#selector').hide();
我强烈建议您花些时间阅读jQueryAPI文档,我相信您可以大大减少所需的代码量

$('#selector').show();
$('#selector').hide();