0
자식 수 x 첫 번째 자식 너비로 요소 스크롤러 너비를 계산하고 싶습니다. 이렇게하려면 지시어 hscroller를 설계했습니다.angularjs 지시문에서 내부 요소에 액세스하는 방법은 무엇입니까?
app.directive('hscroller', function() {
return {
restrict: "A",
link: function(scope, element, attr) {
var pid=$(element).attr("id");
var children = $(element).children();
var id=$(children).attr("id");
var firstChild = $(children[0]);
var width = firstChild.width()*(children.length);
console.log("openPopover hscroller: compute scroller (id="+id
+") width "+children.length+" children of "
+firstChild.width()+"px width, total="+width
+ " (parentid="+pid+")"
);
$(element).css({"width":width+"px"});
}
};
});
실행하는 동안, 그것은 지시어가있는 아이합니다 (ng-와 경쟁 조건이없는 소리를 다음과 같이
<div class="scrollerContainer">
<div id="photos" class="scroller" hscroller="hi!">
<div ng-repeat="photo in stage.photos"
class="imageViewerBackground"
style="background-image: url(rsc/stage/{{stage.id}}/{{photo.file}}.thumb.jpg)"
ng-click="openPopoverImageViewer('#photos', $index)"
>
<div>{{photo.description}}</div>
</div>
</div>
</div>
이 지침은 다음과 같이
html로는 reapeat?), 로그는 다음과 같습니다.
[Log] openPopover hscroller: compute scroller (id=undefined) width 0 children of nullpx width, total=0 (parentid=photos)
나는 이것으로 어떤 생각을 가지고 있습니까?
참고 :이 모든 것은 스크롤 장치 요소의 너비를 조정하여 ipad 장치에 좋은 가로 스크롤러가있을 수 있습니다 (CSS에 수정 사항이 있습니까?).
.hScrollable {
overflow-x: scroll;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
white-space:nowrap;
}
.scrollerContainer {
width: 100%;
height: @popoverScrollHeight;
.hScrollable;
}
.scroller {
overflow: hidden; // this is really important to avoid vertical scrolling on devices
height: @popoverScrollHeight;
}
당신이 propably 달러 (A $) 제한 시간 콜백에서 당신의 연결 코드를 작성하는 것, me.Finally 신뢰는 이미 JQuery와 개체의 경우 JQuery와 객체의 요소를 재 포장 해달라고 이치에 맞지 않는다. – mpm
예제와 함께 plunkr 또는 다른 것을 설정할 수 있습니까? 내 직감은 이것이 확실히 CSS로 수행되어야한다고 말하고있다. – theJoeBiz
전적으로 thetheJoeBiz에 동의합니다. 다음은 CSS 피들입니다. http://jsfiddle.net/stephanedeluca/56gFf/5/ –