English 中文(简体)
当摩擦留下一部分时,去除图像
原标题:Remove an image when mouse leaves a div

我有3X3箱,现在我有这样的箱子,即当你在一片广场上 h时,背景就变成了蓝色,然后当你把箱子 h回空。 我也这样认为,当任何箱子被点击时,就会出现一个形象。 我现在要完成的是,这样,当盒子被点击时,图像就会出现,当同一个盒子被点击时,图像就会消失,因此,将使用Jquery。

在这方面,我已经:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
    <script type="text/javascript">

        $(function () {
            $( .divs ).hover(function () {
                $(this).css("background-color", "#0000EE");
                console.log( hover );

            }, function () {
                $(this).css("background-color", "");
                console.log( hoverout );
            });

            $( .divs ).click(function () {
                $(this).prepend("<img class= divimg  src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/08/SMirC-cool.svg/320px-SMirC-cool.svg.png>");
                console.log( divclicked );
            });
        });

“我目前的页面看像”/

最佳回答

如果有图像,就进行公正的检查

var $img = $("img", this);
if ($img.length > 0)
    $img.remove();
else
    $(this).prepend("<img class= divimg  src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/08/SMirC-cool.svg/320px-SMirC-cool.svg.png>");

如果你不想去掉形象,那么你就只想 visibility看可见度。

var $img = $("img", this);
if ($img.length > 0) {
    $img.toggle();
} else {
    $(this).prepend("<img class= divimg  src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/08/SMirC-cool.svg/320px-SMirC-cool.svg.png>");

}
问题回答

您是否曾尝试过j Query().hide()和j Query()。

另一种选择是使用CSS:hover属性。

.divs:hover {
    background-color: #0000ee;
}

关于点击问题,请在<条码>div上添加图像,并利用j Query乞讨。

<><>超文本:

<div class="divs"><img src="..." alt=""></div>

Java:

$( .divs ).click(function () {
    $(this).children("img").toggle();
});

询问你点击功能中的以下代码:

if($( img.divimg ).length == 0){
  $( img.divimg ).fadeOut(function(){
    $(this).remove()
  });
}else{
  $(this).prepend("<img class= divimg  style= display:none;  src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/08/SMirC-cool.svg/320px-SMirC-cool.svg.png>").fadeIn();
}

另一种选择是(在被点击时)就添加的形象采取行动。

var img = $( <img> )
            .attr( src ,  http://upload.wikimedia.org/wikipedia/commons/thumb/0/08/SMirC-cool.svg/320px-SMirC-cool.svg.png )
            .addClass( divimg )
            .css( display ,  none )
            .bind( click , function(){
                $(this).remove();
            });
$(this).prepend(img);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签