English 中文(简体)
如何在点击 but子时改变某一要素的背景位置
原标题:how to change the background position of an element upon clicking a button
  • 时间:2012-01-12 04:33:40
  •  标签:
  • jquery

OK。 我知道,这个专题已经涵盖数百次。 最后几小时,我尝试了一切。 实际过去几天。 我现在就错了。 因此,不管怎样,都罚款。 我只要求帮助。

Simple task. Click a button to change the position of the object. (I want to actually be able to click a button and then scatter all the list items in a list about the page... but I feel once I figure out how to do this simple task, I can just figure it out from there.

我诚恳地尝试了电子计算机,我在线看到的每条代码变化。 我不知道为什么它不为我工作,但我认为,这必须是因为我 me上yn子。

<p> I want to move this text </p>
<input type = "button" value = "Click me">

<script type = "text/javascript" src = "js/jquery.js"></script>

<script type = "text/javascript">
    $( :button ).click(function() { 
    $( p ).css({backgroundPosition:  100px 0px });
});
</script>

我试图去除 cur。 我尝试了其他变化,包括:

<script type = "text/javascript">
$( :button ).click(function() { 
$( p ).css( backgroundPosition ,  -100px 0px );
});
</script>

无数小时在这里和其他地方只想解决这一简单问题。

我所希望的是ing。 我可以轻而易举地改变背景,但立场有两个坐标可以改变,我不知道为什么我所尝试的任何事情都没有奏效。

Thanks for the help in advance.

问题回答

贵格不入,这部法律是正确的。 问题似乎在于贵方的特性。 考虑对你的法典作以下改动。

$( :button ).click(function() { 
    $( p ).css({ background-color :  blue });
});

Here i ve changed the CSS to update the background color vs. position. This works just fine and is demonstrated in the following fiddle

Fiddle: http://jsfiddle.net/7TuVx/

我将直接将安保科应用到<代码>p的物体上,并看到你需要将其移至适当的位置,然后相应地更新你的酒类编码。

<script type = "text/javascript">
    $( :button ).click(function() { 
        $( p ).css( background-position ,  -100px 0px );
    });
</script>

你们错乱了财产。

<代码>背后源代码系指作为元素背景的图像。 改动不会转移<代码><p> tag。 将内容移至<代码>t和top,但你还需要将<代码>>>>>>>>> 置于相对或绝对的地位。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

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.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签