我已经编写了外部div的代码,我可以上下移动但无法向左移动

时间:2017-10-31 09:35:59

标签: javascript jquery html css pan

请查找附件中的完整代码。 我想平移外部div和内容,因为div有固定的位置。 (功能就像google map pan over)。

imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageCreateInfo.pNext = nullptr;
imageCreateInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
imageCreateInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
imageCreateInfo.extent.width = 1024;
imageCreateInfo.extent.height = 1024;
imageCreateInfo.extent.depth = 1;
imageCreateInfo.arrayLayers = 1;
imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
imageCreateInfo.mipLevels = 0;
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
imageCreateInfo.queueFamilyIndexCount = 0;
imageCreateInfo.pQueueFamilyIndices = nullptr;

});

提前致谢。 jsfiddle

2 个答案:

答案 0 :(得分:1)

Html结构更改

<div class="outterdiv">


</div>
<div class="innerdiv">
  <form action="/action_page.php">
  <label for="male">Male</label>
  <input type="radio" name="gender" id="male" value="male"><br>
  <label for="female">Female</label>
  <input type="radio" name="gender" id="female" value="female"><br>
  <label for="other">Other</label>
  <input type="radio" name="gender" id="other" value="other"><br><br>
  <input type="submit" value="Submit">
</form>
</div>

Css更改

.innerdiv {
  position: fixed;
  z-index: 2;
  left: 20px;
  top: 20px;
}

选中fiddle

答案 1 :(得分:0)

我认为这就是你想要的...... 现在你可以移动,上下左右

<强> CSS:

.outterdiv {
     /* width:2160px; 
      height:3840px; it's remove for clear visualization, you can add it again 
     */ 
      position:absolute;
      background: lightblue;
      //background: url(http://2.bp.blogspot.com/-cdv-Dxy474A/UWMjoBq_vuI/AAAAAAAAFIs/Z4QycYcrkUg/s1600/green-background-pattern-with-warped-vertical-stripes.jpg) left top repeat;
}

<强> jQuery的:

    $(document).ready(function() {
    var self = {};

    $('div').on('mousedown', function(e) {
        self.panStartX = e.pageX;
        self.panStartY = e.pageY;
        self.mouseDown = true;
        self.pageTop = parseInt($(this).css('top'), false) || 20;
        self.pageLeft = parseInt($(this).css('left'), false) || 10;
    }).on('mousemove', function(e) {
        if (self.mouseDown) {
            var pageTop = self.pageTop;
            var pageLeft = self.pageLeft;
            self.panEndX = e.pageX;
            self.panEndY = e.pageY;

            if (self.panStartY > self.panEndY) {
                self.panTop = self.panEndY - self.panStartY;
                pageTop+= self.panTop;
                $(this).css({ top: pageTop });
            } else {
                // Down
                self.panTop = self.panStartY - self.panEndY;

                pageTop-= self.panTop;
                if (pageTop > 42) pageTop = 42;

                $(this).css({ top: pageTop });
            }




            if (self.panStartX > self.panEndX) {
               self.pageLeft = self.panStartX - self.panEndX;                
                pageLeft-= self.pageLeft;              

                $(this).css({ left: pageLeft });
            } else {
                // right

                 self.pageLeft = self.panEndX - self.panStartX;
                pageLeft+= self.pageLeft;
                if (pageLeft > 42) pageLeft = 42;

                $(this).css({ left: pageLeft });
            }
        }
    }).on('mouseup', function(e) {
        self.mouseDown = false;
    });
});

以下是预览链接: https://codepen.io/ziruhel/pen/bYdwYV

更新评论请求的链接: https://codepen.io/ziruhel/pen/OOVQXR