Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. Need Custom Coding for Lay Theme? Find 3rd Party Developers here.
  3. Rotation + ImageHover Addon (I need help on cool javascript effect :)

Rotation + ImageHover Addon (I need help on cool javascript effect :)

Scheduled Pinned Locked Moved Need Custom Coding for Lay Theme? Find 3rd Party Developers here.
4 Posts 3 Posters 181 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johan Saj
    wrote on Dec 5, 2022, 12:35 PM last edited by
    #1

    Hi guys, i love laytheme and the new features that you added on the last update

    I need help!

    I want to use the ImageHover addon (with the fixed centered img position setup) and when the img appears I want it to rotate around its center.

    For now I am using this code:

    <script>
    
    var img = jQuery('.lay-imagehover-region img');
    if(img.length > 0){
        var offset = img. gap();
        function mouse(evt){
            var center_x = (offset.left) + (img.width()/2);
            var center_y = (offset.top) + (img.height()/2);
            var mouse_x = evt.pageX; var mouse_y = evt.pageY;
            var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
            var degree = (radians * (180 / Math.PI) * -1) + 90;
            img.css('-moz-transform', 'rotate('+degree+'deg)');
            img.css('-webkit-transform', 'rotate('+degree+'deg)');
            img.css('-o-transform', 'rotate('+degree+'deg)');
            img.css('-ms-transform', 'rotate('+degree+'deg)');
        }
        jQuery(document).mousemove(mouse);
    }
    
    </script>
    

    But the image is no longer in the right place. And I don't understand javascript code well enough to answer all my questions.

    Would someone be kind to help me?

    Thanks a lot!

    Here is the exemple:
    http://www.rodeo-basilic.johansaj.com/

    K 1 Reply Last reply Dec 5, 2022, 4:25 PM
    0
    • J Johan Saj
      Dec 5, 2022, 12:35 PM

      Hi guys, i love laytheme and the new features that you added on the last update

      I need help!

      I want to use the ImageHover addon (with the fixed centered img position setup) and when the img appears I want it to rotate around its center.

      For now I am using this code:

      <script>
      
      var img = jQuery('.lay-imagehover-region img');
      if(img.length > 0){
          var offset = img. gap();
          function mouse(evt){
              var center_x = (offset.left) + (img.width()/2);
              var center_y = (offset.top) + (img.height()/2);
              var mouse_x = evt.pageX; var mouse_y = evt.pageY;
              var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
              var degree = (radians * (180 / Math.PI) * -1) + 90;
              img.css('-moz-transform', 'rotate('+degree+'deg)');
              img.css('-webkit-transform', 'rotate('+degree+'deg)');
              img.css('-o-transform', 'rotate('+degree+'deg)');
              img.css('-ms-transform', 'rotate('+degree+'deg)');
          }
          jQuery(document).mousemove(mouse);
      }
      
      </script>
      

      But the image is no longer in the right place. And I don't understand javascript code well enough to answer all my questions.

      Would someone be kind to help me?

      Thanks a lot!

      Here is the exemple:
      http://www.rodeo-basilic.johansaj.com/

      K Offline
      K Offline
      kalamakumaran
      wrote on Dec 5, 2022, 4:25 PM last edited by
      #2

      @Johan-Saj

      Haven't tested it but what about adding an animation to the img via css

      .lay-imagehover-region img {
        animation: rotation 5s infinite linear;
      }
      
      @keyframes rotation {
        100% {transform: rotate(360deg);}
      }}
      
      J 1 Reply Last reply Dec 5, 2022, 4:39 PM
      0
      • K kalamakumaran
        Dec 5, 2022, 4:25 PM

        @Johan-Saj

        Haven't tested it but what about adding an animation to the img via css

        .lay-imagehover-region img {
          animation: rotation 5s infinite linear;
        }
        
        @keyframes rotation {
          100% {transform: rotate(360deg);}
        }}
        
        J Offline
        J Offline
        Johan Saj
        wrote on Dec 5, 2022, 4:39 PM last edited by
        #3

        @kalamakumaran
        Thanks a lot for your answer!
        But I think I did not explain myself well enough.

        So:

        I have an image at the center of my screen and i want it to rotate a little bit at the left when my mouse goes on the left of the screen and on the right when my mouse goes on the right of the screen. I also would like the rotation effect to follow the position of my mouse (the more the mouse goes on the left, the more the image rotates)

        I don't know if i made myself clear ?

        My website:
        http://www.rodeo-basilic.johansaj.com/

        1 Reply Last reply
        0
        • A Offline
          A Offline
          arminunruh
          Global Moderator
          wrote on Dec 20, 2022, 2:53 PM last edited by
          #4

          do u have an example website where the effect is shown

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          I also code custom websites or custom Lay features.
          💿 Email me here: 💿
          info@laytheme.com

          Before you post:
          1. When using a WordPress Cache plugin, disable it or clear your cache.
          2. Update Lay Theme and all Lay Theme Addons
          3. Disable all Plugins
          4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

          This often solves issues you might run into

          When you post:
          1. Post a link to where the problem is
          2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
          3. If the problem is difficult to explain, post screenshots / link to a video to explain it
          Online Users
          Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
          laytheme.com
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Recent
          • Tags
          • Popular
          • Users
          • Search