How can I handle a hover the Polymer way without external libraries?

后端 未结 3 785
刺人心
刺人心 2021-02-14 10:42

I figured I would need to do something like:

  • blah
  • because handling clicks looks like this:

    <
    3条回答
    •  没有蜡笔的小新
      2021-02-14 10:55

      on-mouseover and on-mouseout are correct, here's a demo as a Stack Snippet:

      
      
      
      
        
      
        
        
      

      It's possible that your element doesn't have a myHoverHandler property. Perhaps there's a typo?

      As for whether to use Polymer event binding vs other methods, you can absolutely do this with vanilla js or jquery or whatever. Polymer handles a bit of the busy work, like making sure that the event handler is registered in conditional and repeated templates, binding this to the element which is usually what you want, and deregistering the handlers when their elements are removed from the DOM. There are times though when doing it manually makes sense too though.

    提交回复
    热议问题