javascript-events

A “transitionend” event that always fires, and once only

不打扰是莪最后的温柔 提交于 2019-12-22 01:28:51
问题 I need a special transitionend -like event that fires once after all transitions are complete, or fires immediately if there are no transitions defined in the CSS. This what I've come up so far: (function($){ $.event.special.transitionsComplete = { setup: function(data, namespaces, eventHandle){ var queue = [], style = window.getComputedStyle(this, null), computedProps = style.getPropertyValue('transition-property').split(', '), computedDurations = style.getPropertyValue('transition-duration'

Fire event only when clicking on an element, and not on its children

六眼飞鱼酱① 提交于 2019-12-22 00:24:03
问题 If i bind a click handler to the body element, when i click anything on the page the event is triggered. I can check the event.target on every click: $("body").on("click", function(event) { if (event.target.tagName == "BODY") { ... } }); but that seem a bit overkill. Is there a way to trigger the event only when clicking the blank area of the body itself? 回答1: You can use the eventPhase property of event. A value of 2 means that the event is currently triggering the target element: $("body")

How to encapsulate single and temporal events in a service?

陌路散爱 提交于 2019-12-21 21:32:39
问题 I'm trying to encapsulate the events in a service in order to implement a mechanics to subscribe / unsubscribe the listeners when a controller's scope is destroyed. This because I have been using the rootScope.$on in the following way: if(!$rootScope.$$listeners['event']) { $rootScope.$on('event', function(ev, data){ // do some... }); } or $scope.$on('$destroy', function(ev, data){ // unsubscribe the listener }); So I just need one listener of this event, I need to delete the existing

Save HTML5 video currentTime before user leaves or closes page

混江龙づ霸主 提交于 2019-12-21 20:38:30
问题 I would like to save the position of HTML5 video's currentTime to the database when user leaves a web page. It seems like window.onbeforeunload is not a reliable way to do it (not to mention it gives an undesirable popup window!). Is there a better way to do this? I can't think of anything other than saving the position to the server periodically. But that seems wasteful resource/bandwidth wise. Netflix seems to do a good job at remembering your last viewed position. How would they be able to

$(window).load OR $(window).scroll in the same function?

非 Y 不嫁゛ 提交于 2019-12-21 20:37:34
问题 I have implemented stickyfloat (http://plugins.jquery.com/files/stickyfloat_0.htm) on a site. It works great with one gotcha. The function triggers on $(window).scroll and not on $(window).load . I want it to trigger on either because I am linking to anchor points in the page (http://tre-stage.wdogsystems.com:8000/faq/#does-the-sale-of-my-receivables-have-a-negative-effect-on-my-credit-report) and I would like the side menu to appear when the page loads and not just when I initiate a scroll.

Form submitted twice using submit() on keyup

允我心安 提交于 2019-12-21 19:55:07
问题 I had a jQuery / HTML code similar to this: <form action="/SomeAction" method="post"> <input id="my-textbox" type="text" placeholder="Write something and press enter to continue..." /> </form> <script type="text/javascript"> $(function() { $('#my-textbox').keyup(function(e) { var $textbox = $(this); if ($textbox.val().length > 0 && e.keyCode == 13) { $textbox.parent('form').submit(); } }); }); </script> The purpose was to automatically submit the form when the user pressed the "Enter" key. I

The proper way to handle popup closing

╄→尐↘猪︶ㄣ 提交于 2019-12-21 19:26:14
问题 I'm looking for close event for popup. I've found one for XUL, but I need it for HTML. Popup has closed property. >>> var popup = open('http://example.com/', 'popup', 'height=400,width=500'); >>> popup.closed false Well, I can check it once at half second. function open_popup() { var popup = open('http://example.com/', 'popup', 'height=450,width=450'); var timer = setInterval(function(){ if (popup.closed) { alert('popup closed!'); clearInterval(timer); } }, 500); } I've tested it on Chrome 4

The proper way to handle popup closing

痴心易碎 提交于 2019-12-21 19:23:05
问题 I'm looking for close event for popup. I've found one for XUL, but I need it for HTML. Popup has closed property. >>> var popup = open('http://example.com/', 'popup', 'height=400,width=500'); >>> popup.closed false Well, I can check it once at half second. function open_popup() { var popup = open('http://example.com/', 'popup', 'height=450,width=450'); var timer = setInterval(function(){ if (popup.closed) { alert('popup closed!'); clearInterval(timer); } }, 500); } I've tested it on Chrome 4

In Which TextBox is the cursor.?

自作多情 提交于 2019-12-21 17:30:05
问题 I have 4 textboxes and a submit button in my webpage Suppose the user enters data in 2 fields and then clicks the submit button. I now want to know in which textbox the cursor was located just before the submit button was clicked. Any Idea on how to do this in javascript..?? 回答1: Your question does specifically say in javascript , but FWIW here is another option in jQuery: Working jsFiddle here HTML: <input id="in1" type="text" /><br /> <input id="in2" type="text" /><br /> <input id="in3"

How to add an onchange listener for form elements in Ruby on Rails?

天大地大妈咪最大 提交于 2019-12-21 17:24:14
问题 I am writing a form in Ruby on Rails and want to have a select box that calls a Javascript function. In the form file, this is the line I am using to try to add the select box: <%= f.select :question_select, Question.all, :prompt => "New Question", :onchange => "displayQuestion(this)" %> In my application.js file, I just have: function displayQuestion(link) { alert("Changed question"); } I am going to be dynamically adding these form elements to a page, so I can't just use jQuery in the