简体   繁体   中英

jQuery -webkit-transform yAngle

Just as a learning experience, I am trying to make en element rotate on its yAxis upon clicking a link, but I am having no luck. Here is the code I am using. Any ideas?

$('rotate').click(function(){

$('object').style.webkitTransform = "rotateY(90deg)";});

That's not how you apply CSS styles with jQuery. This is .

$('rotate').click(function ()
{
    $('object').css('-webkit-transform', 'rotateY(90deg)');
    // or this:
    // $('object').attr('style', '-webkit-transform: rotateY(90deg)');
});

.style isn't a jQuery object property, if you wanted to affect one, use [0] like this:

$('.rotate').click(function(){
  $('.object')[0].style.webkitTransform = "rotateY(90deg)";
});

Or, to affect all of them use a .each() :

$('.rotate').click(function(){
  $('.object').each(function() {
    this.style.webkitTransform = "rotateY(90deg)";
  });
});

Note that your selectors 'rotate' and 'object' are looking for <rotate> and <object> elements...so you'll want to adjust those selectors accordingly, above I'm looking for class="rotate" for the click, etc.

An alternative more jQuery-ish way (debatable for custom properties) is .css() , like this:

$('.rotate').click(function(){
  $('.object').css("webkitTransform", "rotateY(180deg)");
});

You can test it here .

The QTransform jQuery plugin extends jQuery's css to include setting css Transforms. You can write: $('object').rotate('30deg'); or animate with $('object').animate({rotate:'+=30deg', 1000});

http://plugins.jquery.com/project/QTransform

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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