JQuery - How to detect if a div includes a special position

I have 2 divs like <div class="parent"<div class="child"></div></div>. First I need to know the horizontal center of the "parent" div.

var offset = $('.parent').offset(),
    width = $('.parent').width(),
    parentCenter = offset.left + width / 2;

Now, I need to know if the "child" div passes or includes this position. Example: The parent div is a wrapper and the child div is a image that should be bigger if it passes the center of the parent. (the child is moveable by a slide effect)


The child will intersect with that position if its left corner is further left AND the right corner is further right than the position you already calculated:

var child = $('#child');

// Get X coordinates of child's corners
var leftX = child.offset().left;
var rightX = leftX + child.width();

if (leftX <= parentCenter && parentCenter <= rightX) {
    // child overlaps with parent's center (on the X axis)

Need Your Help

Mac Deleting Multiple Files Bash

macos bash shell uninstall uninstaller

I'm trying to uninstall a program by deleting all of the files the installer installed. This is the script I have tried, but it returns a "Too many arguments" error on line 6 (highlighted with **) ...

Multiple Annotations from NSMutableArray in mapkit

ios ipad mkannotation cllocation mapkit

I have a mutablearray that is populated from sqlite db in ios. I have gotten the annotations to load and view properly. My question is how can I write a loop that will add annotations with the si...