-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
建议适配容器的缩放功能 #6
Comments
非常感谢你提出的建议 <vdr
v-for="(item,index) in elements"
:parent="true"
:x="item.x * proportion"
:y="item.y * proportion"
:w="item.width * proportion"
:h="item.height * proportion"
:z="item.zIndex"
:key="item.id"
:snap="true"
:snap-tolerance="5"
:is-conflict-check="item.isCheck">
</vdr> 这样即不用去改变组件,又能根据窗口大小进行动态修改缩放比例。 |
你好,你所说的做法我一开始尝试过,但是这样只能改初始的位置大小并不能解决drag和resize的问题,后面变化的时候因为div被缩放了,导致实际鼠标的偏移量和div变化值并不相等,所以会出现鼠标指针与handle的距离越来越远,我还尝试了很多在resizing事件中修正偏移量的做法,也不能完美解决,于是才想到要去修改snapToGrid方法 |
应该还要配合 |
感谢你的理解,需要满足的场景是无论放大或缩小父容器,原先的布局块都可以无缝衔接,拖拽和改变大小功能都能正常使用,如果有更好的方案也希望赐教 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
留个demo代码供后来者参考。 <template>
<div id="app">
<div :style="`height: 1080px; width: 1920px; border: 1px solid red; position: relative; transform:scale(${scaleRatio})`">
<vue-draggable-resizable :w="400" :h="300" @resizing="onResizing" @dragging="onDragging" :parent="true" :debug="false" :scaleRatio="scaleRatio">
<p>
left: {{left}}<br/>
top: {{top}}<br/>
width: {{width}}<br/>
height: {{height}}
</p>
</vue-draggable-resizable>
</div>
</div>
</template>
<script>
import VueDraggableResizable from './components/vue-draggable-resizable'
import './components/vue-draggable-resizable.css'
export default {
name: 'app',
components: {
VueDraggableResizable
},
data () {
return {
scaleRatio: 0,
left: 0,
top: 0,
width: 0,
height:0
}
},
mounted () {
let windowWidth = window.innerWidth
this.scaleRatio = (windowWidth / 1920).toFixed(2)
window.onresize = (e) => {
this.setScaleValue()
}
},
computed: {
},
methods: {
setScaleValue () {
let windowWidth = window.innerWidth
this.scaleRatio = (windowWidth / 1920).toFixed(2)
},
onResizing(left, top, width, height){
this.left = left
this.top = top
this.width = width
this.height = height
},
onDragging(left, top){
this.left = left
this.top = top
}
}
}
</script>
<style>
.vdr {
border: 1px dashed black;
}
</style>
|
这样直接除会有精度丢失问题吧,不能被整除部分精度就丢了 |
你好,最近在使用该组件做大屏展示功能,为了在小屏幕展示我的页面需要进行缩放,但是缩放后导致拖拽和调整大小都会出现鼠标指针便宜的问题,本地调试的解决方案是,在组件上新增一个scaleRatio属性,在页面中计算出缩放比例传给组件,在组件的snapToGrid方法中return [x/this.scaleRatio, y/this.scaleRatio],即可适配缩放,请考虑采纳该方案,谢谢
The text was updated successfully, but these errors were encountered: