【问题标题】:Flip an image when a table cell is clicked, or the image itself is clicked单击表格单元格或单击图像本身时翻转图像
【发布时间】:2013-11-01 04:03:05
【问题描述】:

如果单击单元格或单击图像本身,我会尝试将箭头翻转 180 度。这是我的代码: 注意:被翻转的图像是第一行中 ID 为 image1 的图像。一旦我得到第一个工作,我将翻转所有图像。

<thead>
            <tr>
                <th style="text-align:left; padding-top: 20px;" width="10%" title="Sort by Symbol">Symbol <img src="/images/sort-arrow.jpg" title="Sort by Symbol" alt="Sort by Symbol" class="sort-right move-left bottom-image" id="image1"/></th>
                <th style="text-align:left;" width="20%" title="Sort by Company Name">Company<br><span class="move_right">Name</span> <img src="/images/sort-arrow.jpg" title="Sort by Company Name" alt="Sort by Company Name" class="sort-right move-left"/></th>
                <th style="text-align:center;" width="12%" title="Sort by Buy Date"><span class="center-text">Buy</span><br>Date <img title="Sort by Buy Date" src="/images/sort-arrow.jpg" alt="Sort by Buy Date"/></th>
                <th style="text-align:center;" width="10%" title="Sort by Buy Price"><span class="center-text">Buy</span><br>Price &nbsp;<img title="Sort by Buy Price" src="/images/sort-arrow.jpg" alt="Sort by Buy Price"/></th>
                <th style="text-align:center;" width="9%" title="Sort by Closed Price"><span class="center-text">Closed</span><br>Price &nbsp;<img title="Sort by Closed Price" src="/images/sort-arrow.jpg" alt="Sort by Closed Price"/></th>
                <th style="text-align:center;" width="9%" title="Sort by Closed Date"><span class="center-text">Closed</span><br>Date &nbsp;<img title="Sort by Closed Date" src="/images/sort-arrow.jpg" alt="Sort by Closed Date" /></th>
                <th style="text-align:center;" width="10%" title="Sort by Current Return"><span class="center-text">Total</span><br>Return &nbsp;<img title="Sort by Current Return" src="/images/sort-arrow.jpg" alt="Sort by Current Return"/></th>
        </thead>

还有 Javascript:

$(function(event){
    $("table .title a").tooltip({ bodyHandler: function(event) { return $($(this).attr("href")).html(); }, showURL: false, track: true, delay: 0 });
});

var value = 0
$("#image1").rotate({ 
   bind: 
     { 
        click: function(){
            value +=180;
            $(this).rotate({ animateTo:value})
        }
     } 

});

我正在使用jQuery Rotate 插件

有什么建议吗?

再次重申:如果单击图像,或者图像所在的 CELL 被单击,图像应该进行 180 度翻转。

【问题讨论】:

  • 您的代码运行良好jsfiddle.net/9FMks/1
  • 不,你看,当他们在表格单元格内单击时,我希望图像旋转。再次确认:当他们单击图像时,图像应该旋转,或者如果他们单击图像所在的单元格。 @Manish
  • 点击图片时正在旋转
  • 当您单击图像或@Manish 中的单元格时
  • 你需要添加 $("#image1").rotate 在点击http://jsfiddle.net/9FMks/2/

标签: javascript jquery html css


【解决方案1】:

您需要在“th”.click 中添加 .rotate 并在 image1 .click 上添加 preventPropagation 像这样

var value = 0
$("th:first").click(function(){//you can add some class or id the first th or select only the first
    value +=180;
    $("#image1").rotate({ animateTo:value});//or $(this).find("img")
});
$("#image1").rotate({ 
   bind: 
     { 
        click: function(e){
            e.stopPropagation();//or the image will rotate 360
            value +=180;
            $(this).rotate({ animateTo:value})
        }
     } 

});    

http://jsfiddle.net/9FMks/2/

【讨论】:

  • 谢谢!问题虽然,我正在尝试将它实现到其他列,但是当我将它添加到其他列(更改值,行的 id 选择器)它不起作用......你可以使用这个例子并制作它在两列上工作,这样我就可以看到你是怎么做到的?感谢@AbrahamUribe 的帮助
猜你喜欢
  • 1970-01-01
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 2021-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
相关资源
最近更新 更多