在多个元素的public void handleFileUpload(FileUploadEvent event) throws IOException {
uploadedFile = event.getFile();
File directory = new File(rootPath + TEMP_DIRECTORY);
directory.mkdirs();
String filename = FilenameUtils.getBaseName(UUID.randomUUID().toString());
String extension = FilenameUtils.getExtension(uploadedFile.getFileName());
Path file = Files.createTempFile(directory.toPath(), filename + "-", "." + extension);
Files.copy(uploadedFile.getInputstream(), file, StandardCopyOption.REPLACE_EXISTING);
imageFilePath = TEMP_DIRECTORY + "/" + file.getFileName().toString();
FacesMessage message = new FacesMessage("Succesful", imageFilePath + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
public void crop() throws IOException {
if (image == null) {
return;
}
String imageName = URLUtils.slugify(StringUtils.transliterateRu2En(name));
String croppedImagePath = IMAGES_ROOT_DIRECTORY + "/" + categoryId + "/" + levelId;
File directory = new File(rootPath + croppedImagePath);
directory.mkdirs();
String filename = FilenameUtils.getBaseName(imageName);
String extension = FilenameUtils.getExtension(image.getOriginalFilename());
Path file = Files.createTempFile(directory.toPath(), filename + "-", "." + extension);
InputStream is = new ByteArrayInputStream(image.getBytes());
Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING);
croppedImageFileName = file.getFileName().toString();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Success", "Cropping finished."));
}
中,我想滚动条形图以查看所选项目始终位于顶部。此项目已分配ul
课程。到目前为止,我已设法将栏滚动到此元素的位置,但不将其滚动到容器的顶部。
我的代码是:
selected
有什么想法吗?
答案 0 :(得分:1)
遍历parent
元素,如下所示:
jQuery(document).ready(function(){
var x = jQuery('li.selected').parent();
jQuery('#container').animate({
scrollTop: jQuery(x).offset().top
}, 2000);
});
我在类似情况下使用过这种情况:无法直接在scrollTop
...行中进行遍历,因此我使用变量选择父变量并将此变量放入scrollTop
线。