gpt4 book ai didi

javascript - 拖放 modalPanel 的内部

转载 作者:行者123 更新时间:2023-11-29 20:23:42 25 4
gpt4 key购买 nike

使用 Richfaces 3.3.0GA、jsf 1.2_14 和 facelets。

我有一个 richfaces ModalPanel,里面有一个图像,如下所示:

<ui:composition>
<a4j:outputPanel id="#{prefix}_a4jImagePanel">
<rich:modalPanel id="#{prefix}_imagePanel" autosized="true" domElementAttachment="body" rendered="#{examinationPanel.render}">
<f:facet name="header">
<h:outputText value="Images from examination" />
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/images/modal/close.png" id="#{prefix}_hideimagelink" styleClass="hidelink" />
<rich:componentControl for="#{prefix}_imagePanel" attachTo="#{prefix}_hideimagelink" operation="hide" event="onclick" />
</h:panelGroup>
</f:facet>
<a4j:form>

<h:panelGrid columns="1" id="picture">

<!-- big image here -->
<rich:dragSupport ondragstart="startDrag(event)" ondragend="stopDrag(event)">
<h:graphicImage id="#{prefix}_pic" value="#{examinationPanel.imagePath}" onmousedown="startDrag(event)" onmouseup="stopDrag(event)" /></rich:dragSupport>

<rich:contextMenu event="oncontextmenu" attachTo="#{prefix}_pic" submitMode="none">
<rich:menuItem value="Zoom In" onclick="enlarge();" id="zin"/>
<rich:menuItem value="Zoom Out" onclick="decrease();" id="zout"/>
</rich:contextMenu>

</h:panelGrid>
</a4j:form>
</rich:modalPanel>
</a4j:outputPanel>
<script type="text/javascript">
//adding the event listerner for Mozilla

if(window.addEventListener)
document.addEventListener('DOMMouseScroll', zoomScroll, false);
//for IE/OPERA etc
document.onmousewheel = zoomScroll;
var startX;
var startY;
function enlarge(){
#{rich:element(fnc:concat(prefix,'_pic'))}.width=#{rich:element(fnc:concat(prefix,'_pic'))}.width*1.25;
}
function decrease(){
#{rich:element(fnc:concat(prefix,'_pic'))}.width=#{rich:element(fnc:concat(prefix,'_pic'))}.width*0.8;
}
function zoomScroll(event){
var delta = 0;

if (!event) event = window.event;

// normalize the delta
if (event.wheelDelta) {

// IE and Opera
delta = event.wheelDelta / 60;

} else if (event.detail) {

// W3C
delta = -event.detail / 2;
}
if(delta>0)enlarge();
else decrease();
}

function startDrag(event){

startX = event.clientX;
startY = event.clientY;


}
function stopDrag(event){

var diff = new ModalPanel.Sizer.Diff();
diff.deltaHeight=0;
diff.deltaWidth=0;
diff.deltaX = -startX+event.clientX;
diff.deltaY = -startY+event.clientY;

#{rich:element(fnc:concat(prefix,'_imagePanel'))}.component.doResizeOrMove(diff);
}
</script>
</ui:composition>

我希望图像可以缩放(因此需要 enlarge() 和 decrease() 函数)并且可以拖动。此代码部分工作。如果您在缩放之前免打扰,它可以正常工作,但之后它会停止工作。顺便说一句,我看不到拖动的预览。我想实现与 modalPanel 的标题使用的相同的 DND(这给人移动真实窗口的印象,您会看到窗口内容在拖动时移动)。

我怎样才能实现它?

最佳答案

我无法让它与 richfaces modalPanel 一起工作,但我可以让它与 primefaces 对话框一起工作,这非常相似。这是解决方案:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fnc="http://eyeprevent.com/fnc" xmlns:p="http://primefaces.prime.com.tr/ui">
<head>
<script type="text/javascript">
//adding the event listerner for Mozilla

if(window.addEventListener)
document.addEventListener('DOMMouseScroll', zoomScroll, false);
//for IE/OPERA etc
document.onmousewheel = zoomScroll;
var startX;
var startY;
function enlarge(){
#{rich:element('pic')}.width=#{rich:element('pic')}.width*1.25;
}
function decrease(){
#{rich:element('pic')}.width=#{rich:element('pic')}.width*0.8;
}
function zoomScroll(event){
var delta = 0;

if (!event) event = window.event;

// normalize the delta
if (event.wheelDelta) {

// IE and Opera
delta = event.wheelDelta / 60;

} else if (event.detail) {

// W3C
delta = -event.detail / 2;
}
if(delta>0)enlarge();
else decrease();
}
</script>

</head><body>
<p:resources />

<a4j:outputPanel id="a4jImagePanel">
<p:dialog id="imagePanel" widgetVar="dialog">
<p:draggable dragOnly="true" underlay="none"/>
<a4j:form>
<h:panelGrid columns="1" id="picture">

<!-- big image here -->

<h:graphicImage id="pic" value="/images/eye.jpg"></h:graphicImage>

<rich:contextMenu event="oncontextmenu" attachTo="pic" submitMode="none">
<rich:menuItem value="Zoom In" onclick="enlarge();" id="zin"/>
<rich:menuItem value="Zoom Out" onclick="decrease();" id="zout"/>

</rich:contextMenu>
</h:panelGrid>
</a4j:form>
</p:dialog>

</a4j:outputPanel>


<a href="#" onclick="dialog.show()">Link</a>
</body>
</html>

关于javascript - 拖放 modalPanel 的内部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2424159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com