jquery ui draggable accordion stick to mouse in Chrome - javascript

I am working on a jquery ui website and have a draggable accordion div that experiences an odd behavior with the mouse sticking only to the scroll bars.
$("#item_accordion").draggable();
This behavior seems to only occur in Google Chrome which is stranger yet. I can eventually get the mouse to let go of the accordion by doing a right-click and moving the mouse quickly. I was curious if anyone have experience, and hopefully solutions, with this isse.
Thanks so much,
Derek

I've had the same issue. Unfortunately I don't know what's causing it since I didn't want to dig too much into JQuery but I was able to work around it by specifying a "handle" for my draggable object. The "handle" is the only place where a drag can be initiated and since my "handle" didn't contain a scrollbar I no longer had this issue.
$('#overlays_dialog').draggable({handle: '.dialog-header'});
overlays_dialog is a div containing a child div with a class of '.dialog-header'.

Related

How can I make .hover() work with a swiping finger on a touch device?

So, here's the thing. I am using this library
This works by having a container div full of img elements, and changing their respective z-index depending on the mouse position while hovering the container. My goal is for it to work with a swiping finger instead of a hovering mouse.
After a fair bit of research I only found solutions similar to this, but it does not help me because my library uses .hover() in jquery and not the css :hover state.
I also tried mmy luck with an .ontouchmove replacing the .hover() but it broke the whole thing, I'm pretty sure I did not even use it correctly, I am am pretty lost with javascript without jquery.
So how could I possibly simulate/make this work with swiping a finger on the screen ? I'm a bit lost :(

How Do I Suppress Scrolling On Mouse Drag?

There are a number of ways for a user to scroll a browser window, but there's one I find particularly irksome and would like to suppress. This would be where you click with the mouse and then drag the mouse outside of the window and it scrolls in the direction the mouse has been dragged.
This behavior is particularly annoying because the page I'm working on does things on both mousedown and mousemove, so its fairly easy for the user to be in the middle of this operation and slip off the page and screw up what they were doing. I can't just overflow: hidden because I do want the user to be able to scroll, just not by this particular method.
I could imagine lots of apps where this is a problem; for instance, click and drag away from center to zoom on the current frame of content with existing scrollbars might even want to support the mouse leaving the window via capture-mode events, but this will cause it to scroll!
The only thing I can think to do is do { overflow: hidden } and then implement custom scrollbars, but custom scrollbars tend to suck. I've been searching around for awhile and trying different things, but haven't seen a solution to this. Pardon if it's a dupe and I just didn't find the original.
I found a reasonable answer to your question here: Disabling middle click scrolling with javascript
It seems that it's possible on certain browsers, but you might want to just tell people not to do that. It's not a very common action anyways.

custom scrollbar not working on touch device

following problem. im using a simple jquery plugin located here
it works fine so far, problem is when im testing it on a touch device (eg ipad2) its not possible to scroll within a div. it does not work with 2 finger swipe too!
i guess the behaviour is not the same to the "standard" scrollbar. but is there any solution to make this touchable?
im in the testing phase, which means the body code is pretty simple
$(document).ready(function() {
function appenddiv() {
var $scrolling = $('<div id="test" class="scrolling">A lot of text in here ...<div id="scroll2"><img src="../images/31670035.jpg"></div></div>');
$scrolling.appendTo($('#container')).scrollbar();
}
$('#scrollbar-link').on('click', function() {
appenddiv();
});
});
<body>
Klick mich!
<div id="container">
</div>
</body>
Do i need something like a "touchable" script which makes it possible to swipe the scroller?
Thanks
:-) Yes, this is definetly an issue...
The root problem is the following:
To create custom scrollbars you need to make DIV overflow: hidden - to hide sys scrollbars. This is OK. BUT on mobile (iPad too) devices from this point your DIV will not be scrollable. It will be (only), if you use overflow: auto ... This is logical - more or less. But drives you to the headache you have now :-)
So, you have to make a choice at this point..
a) you forget your custom scrollbar on touch devices - keep overflow: auto there
b) you implement a drag&drop feature manually - if you detect a mobile device
version b) would be tricky - again. since the event we know as "mousedown" event works differently on touchscreens. There is not only one mousedown - in fact there may be an array of "mousedown"s since you touche the screen with your finger, then you touch the screen with another finger, and so on... so on touchscreens this is a touch[] array...makes sense absolutely, but complicates things...
Either way, I don't know about any less complex solutions... If anyone does, I'm curious about that too!! :-)
We did a lot of testing and put many effort into this issue (and to other issues too) while was working on our NiceScrollbars library project...
I'm here if you would like to discuss this problem deeper! Will try to help
Either way, I don't know about any less complex solutions... If anyone
does, I'm curious about that too!! :-)
In theory, we could add a div with opacity=0.000000000001, z-index -1 (-1 index from the original div. i.e. the original div has a z-index of 10, then the new div would have a z-index of 9) and scroll=auto. The new div would be a copy of the div with scroll=hidden attributes in terms of content and css.
The scroll event would fire via the hidden div and then update the visible div.
Too bad we have to go to that extend, but it seems to be another clean solution/hack beside the fact that you have to duplicate the content or create an element that holds the content height.

How to emulate this javascript functionality (movable div and saved positions)

I have seen a feature on a site I would like to emulate. I have intermediate php skill but am a novice javascript user. The feature is the site content displayed in divs which can be moved around on the screen and their position saved using cookies. This site: [url]www.nowgamer.com[/url] is where I saw it (latest podcasts, videos, reviews etc with filter)
How would I go about achieving this through javscript? I want to know how to connect javascript with the cookie so that the positions of the square divs are saved, as are the preferences of the content filter on each div. How can I achieve this?
Would this be a big job? Thank you for any help, I am working independently on this in my spare time so your contribution with advice is my lifeline.
As Zoidberg commented, its easy with JQuery or Yui, or any other javascript library that provides drag & drop functionality. They are almost easy to configure, checking at demo they give. They also expose certain events like beforeDrag, afterDrag, onDrop, etc. where you can fire a simple js function check the elements' dropped position store it in cookies. For setting cookies, there are world of code on internet.
Also, you might want to check floating absolute/relative positioning css, if your DOM divs are going to be floating around the page.
GoodLuck.
simplyharsh has the proper answer, but I'd like to expand on it a bit:
The basics of a draggable div aren't too complicated. You attach an onclick handler to initiate the dragging. Internally, that's accomplished by changing the div's CSS so it's position: absolute. Then you start monitoring mouse movements (basically onmousemove) and changing the div's top and left according to the movements you've captured.
Dropping is a bit more complicated. You can always just release the mouse and leave the div wherever you ended up moving it, but that leaves it absolutely positioned and therefore outside of normal document flow. But dropping it "inside" some other element means a lot of prep work.
Because of how mouseover/mouseout/mouseenter events work, they WON'T work while you're dragging an element - you've got your draggable div under the mouse at all times, so there's no mouseenter/leave events being fired on the rest of the page. jquery/mootools and the like work around it letting you specify drop zones. The locations/sizes of these zones are precalculated and as you're dragging. Then, as you're dragging, the dragged object's position is compared to these precalculated drop zone locations for every move event. If you "enter" one of those zones, then internally the libraries fire their mouseenter/mouseleave/mouseover events to simulate an actual mouseenter/leave/over event having occured.
If you drop inside a zone, the div gets attached as a child of that zone. If you drop outside, then it will usually "snap back" to where it was when you initiated the drag.
Resizing is somewhat similar, except you're adjusting height and width instead of top and left.

How can I temporarily prevent a scrollable div from scrolling?

Here is my current situation:
I have a web page containing a couple scrollable divs. Each of those divs contains a number of objects. I am using YUI to display popup menus of actions that can be performed on each object. Each object has its own menu associated with it that is constructed and displayed dynamically. The popup menus can be large and can overlap the bounds of the scrollable div.
From what I believe are issues with focus (the menus must be accessible), when I hover the mouse over an action that lies on top of an edge of the scrollable div, the div automatically scrolls, moving the content but leaving the menu stationary. Trying to move the menu dynamically when this happens is not something I want to do as I believe it would provide a poor user experience.
So I need to prevent this focused menu from scrolling the div. My idea for providing the best user interface is to prevent these inner divs from scrolling when a menu is open. This leaves the menu positioned in the optimal location to show the user which item is being acted upon. If the user wants to scroll the box, they can click to close the menu and then scroll normally.
How can I do this? I need a solution that works across the major browsers.
My first thought was to listen to the onscroll event for that particular element. Unfortunately, there does not seem to be an easy way from there to just prevent the scrolling from happening. For one, my JavaScript event code appears to execute after the actual scrolling has occurred.
Then, I thought that since my code is being run after the object has scrolled, I could just reset obj.scrollTop and obj.scrollLeft. Sure enough, this appears to work, though I am worried that on slow browsers the user will see the content inside the div "jump around". Also, it would be really nice if the amount the element scrolls is part of the event object. Is it stuck in there somewhere? I'm looking for an alternative to having to store the scrollTop and scrollLeft variables for this element and then using them while the scrolling is temporarily disabled.
What is the best way to solve this entire problem?
I agree with Anthony regarding the presentation of the functionality you're trying to disallow. If you're going to disable scrolling, then you should make that part of the page visually disabled or removed.
To that end, you can position a semi-transparent div on top of the scrollable div in question, which would capture the mouse events and visually show that the scrollable div is inactive for now. It would be hard to make cross-browser compatible and wouldn't be perfect, but then again very few client-side tricks like this are.
The simple answer is no you can't do this. Its doubly no if you want a cross-browser solution.
Providing the user with the clear affordance that something can be scrolled then denying them that is just plain poor UI design.
Ok so after your edit it turns out you are not actually trying to prevent the user from scrolling.
The main answer remains true though. It sounds as though the focus is going to rectangle (probably an anchor?) that is not fully in view and causes a scroll. Is there a reason this rectangle must get the focus? For accessibility?
What if you didn't have overflow: scroll and instead you used overflow: hidden and provided scroll up/down buttons that allowed the user to scroll when necessary? These buttons could of course be disabled easily.
Though it may not be the answer you are looking for, if you are to set the display value of the div to 'none' while the page loads (from the server) and then have an event wired to the page load (either pageLoad in ajax.net or attach it to the onload event via javascript) that will make the div display set to 'block' .. that would ensure that slower browsers wouldn't see the div 'jumping around' (could even put a 'loading' image in the div to show users it's doing something and not just invisible)
sorry i couldn't provide a more complex/fluent solution.
I found a way to work around this issue. By removing the menu element from the scrollable div and then appending it directly to document.body, the browsers all stop trying to scroll the div to reveal the focused element (even though the element is already completely visible).
Thanks to all for your time and your answers!

Categories