最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - get the width of the html element with this event - Stack Overflow

programmeradmin4浏览0评论

This meteor client code needs the width of the element for which the event happened but failed to get it. How can it be done? Thanks

Template.swipe.events({
  'mouseup .swipe': function(e) {
    utility.mouseUp(e);
  }
});

utility = (function () {

  return {
    mouseUp: (event) => {
      console.log(event.currentTarget.width);
    }
}());

This meteor client code needs the width of the element for which the event happened but failed to get it. How can it be done? Thanks

Template.swipe.events({
  'mouseup .swipe': function(e) {
    utility.mouseUp(e);
  }
});

utility = (function () {

  return {
    mouseUp: (event) => {
      console.log(event.currentTarget.width);
    }
}());
Share Improve this question asked Jul 25, 2016 at 5:14 Fred J.Fred J. 6,04913 gold badges60 silver badges113 bronze badges 3
  • 1 DOM nodes don't have a width property. Did you mean offsetWidth? – John Dvorak Commented Jul 25, 2016 at 5:18
  • use .width() property. – Ronak Patel Commented Jul 25, 2016 at 5:22
  • @JanDvorak - offsetWidth wasn't the solution for me. However your link revealed the correct property I was searching for: scrollWidth. Just in case someone else has the same problem! – MerlinK Commented Feb 14, 2017 at 14:20
Add a ment  | 

1 Answer 1

Reset to default 5

Use the event.currentTarget.offsetWidth property instead of width.

发布评论

评论列表(0)

  1. 暂无评论