简体   繁体   English

使用javascript和jquery ui在点击时激活CSS

[英]active css on click using javascript and jquery ui

Totaly new on javascript ! javascript全新! I'm trying to apply a :active class when clicking on ui window. 我正在尝试在ui窗口上单击时使用:active类。 (blur effect), instead of modal effect. (模糊效果),而不是modal效果。

My css: 我的CSS:

.blur:active {
  -webkit-filter: blur(5px);
  -moz-filter: blur(5px);
  -o-filter: blur(5px);
  -ms-filter: blur(5px);
  filter: blur(5px);
}

My html: 我的html:

<!-- popup -->
        <div id="dialog" title="title">
         <h3><center>Text</center></h3>
        </div>
<!-- img -->    
<img class="blur" src="img/IMG_0125.png" alt="" width="100%">

The javascript: JavaScript:

<link rel="stylesheet" href="jquery/css/jquery-ui.css" />
<!-- <script src="jquery/ui/jquery-ui.js"></script> -->
<script src="jquery/ui/jquery-ui.min.js"></script>

<script type="text/javascript">
        $(function(){
            $( "#dialog" ).dialog({
                autoOpen: false,
                modal: true,
                bgiframe: true,
                height: 350,
                width: 400,
                position: 'center',
                show: {
                 effect: "fade",
                 duration: 1000
                },
                hide: {
                 effect: "fade",
                 duration: 400
                }, 
                resizable: false,
                buttons: {
                    'OK': function() {
                        $(this).dialog('close');
                    }
                }
            });
            $('#popup').click(function() {
                $('#dialog').dialog('open');
            });
            /*The code works until here*/
            $('#popup').click(function(){
                $(this).parent().addClass('active').siblings().removeClass('active');
            });
        });    
    </script>

The jsfiddle link: https://jsfiddle.net/5g9t5h2d/# jsfiddle链接: https ://jsfiddle.net/5g9t5h2d/#

A click on the image works, the image is bluring, but not when the window appear: How to blur the image when the window appear ? 单击图像有效,图像模糊,但是当窗口出现时不模糊:如何在窗口出现时使图像模糊?

Just found a solution with .blur.active { } in the css, and this code: 刚在css中找到了.blur.active { }的解决方案,并且此代码为:

$(function(){
            $("#dialog").dialog({
                autoOpen: false,
                modal: false,
                bgiframe: true,
                height: 350,
                width: 400,
                position: 'center',
                show: {
                 effect: "fade",
                 duration: 1000
                },
                hide: {
                 effect: "fade",
                 duration: 400
                }, 
                resizable: false,
                buttons: {
                    'OK': function() {
                        $(this).dialog('close');
                        $('.blur').removeClass('active');
                        $(this).addClass('active');
                    }
                }
            });
            $('#popup').click(function() {
                $('#dialog').dialog('open');
            });
            $('#popup').click(function() {
                $('.blur').addClass('active');
                $(this).removeClass('active');
            });
        });

Demo: https://jsfiddle.net/5g9t5h2d/2/ 演示: https : //jsfiddle.net/5g9t5h2d/2/

Thanks all for your help ! 感谢你的帮助 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM